From de3ed3f77b55e8e86b007f107431f50b0d6ea7d6 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Thu, 12 Oct 2023 10:08:16 +0100 Subject: [PATCH] use cards in directory listings --- src/components/DirectoryListing.astro | 38 +++++++++++++++++++++++++++ src/pages/[...slug].astro | 23 +++++++--------- 2 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/components/DirectoryListing.astro diff --git a/src/components/DirectoryListing.astro b/src/components/DirectoryListing.astro new file mode 100644 index 00000000..ab675dd8 --- /dev/null +++ b/src/components/DirectoryListing.astro @@ -0,0 +1,38 @@ +--- +import type { NavDirectory, NavEntry } from "@/lib/nav"; + +interface Props { + dir: NavDirectory; +} + +const { dir } = Astro.props; + +function getEntrySubtitle(entry: NavEntry): string | undefined { + if (entry.type === "file") { + return entry.collectionEntry.data.subtitle; + } + return undefined; +} +--- + + diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index a72166e9..7283bb30 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -1,8 +1,14 @@ --- // Docs page +import DirectoryListing from "@/components/DirectoryListing.astro"; import DocsArticle from "../layouts/DocsArticle.astro"; -import { getRootNav, flattenNav, type NavEntry } from "../lib/nav"; +import { + getRootNav, + flattenNav, + type NavEntry, + type NavDirectory, +} from "../lib/nav"; export async function getStaticPaths() { const entries = flattenNav(await getRootNav()); @@ -35,18 +41,9 @@ const rendered = await collectionEntry?.render(); rendered ? ( ) : ( - /* Directory listing */ - navEntry.type === "directory" && ( - - ) +
+ +
) }