From 4660eb323e7ca8c20aad20780af15506c0d88852 Mon Sep 17 00:00:00 2001 From: Alex Stephen <1325798+rambleraptor@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:51:24 -0700 Subject: [PATCH] Info panel (#39) * wip * add info panel * forgot to add new components --- astro.config.mjs | 3 +- scripts/generate.ts | 2 + src/components/InfoPanel.astro | 59 +++++++++++++++++++ .../overrides/TableOfContents.astro | 6 ++ src/content/config.ts | 15 ++++- 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 src/components/InfoPanel.astro create mode 100644 src/components/overrides/TableOfContents.astro diff --git a/astro.config.mjs b/astro.config.mjs index 2f6add6..dd304cf 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -28,7 +28,8 @@ export default defineConfig({ sidebar: sidebar, components: { 'Head': './src/components/overrides/Head.astro', - 'SkipLink': './src/components/overrides/SkipLink.astro' + 'SkipLink': './src/components/overrides/SkipLink.astro', + 'TableOfContents': './src/components/overrides/TableOfContents.astro' } }), tailwind({ diff --git a/scripts/generate.ts b/scripts/generate.ts index e5adde3..d569d18 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -92,6 +92,8 @@ function buildAEP(files: string[], folder: string): AEP { contents.frontmatter['prev'] = false; contents.frontmatter['next'] = false; + contents.frontmatter['isAEP'] = true; + // Write everything to a markdown file. return { title: yaml.title, diff --git a/src/components/InfoPanel.astro b/src/components/InfoPanel.astro new file mode 100644 index 0000000..ff75fab --- /dev/null +++ b/src/components/InfoPanel.astro @@ -0,0 +1,59 @@ +--- +const props = Astro.props.entry; + +function formatDate(date: Date): string { + const options: Intl.DateTimeFormatOptions = { + year: "numeric", + month: "long", + day: "numeric", + }; + + return date.toLocaleDateString(undefined, options); +} + +const depth = 0; +--- +{ + props.data.isAEP === true && ( +
+ +
+ ) +} + + diff --git a/src/components/overrides/TableOfContents.astro b/src/components/overrides/TableOfContents.astro new file mode 100644 index 0000000..ed1ed98 --- /dev/null +++ b/src/components/overrides/TableOfContents.astro @@ -0,0 +1,6 @@ +--- +import Default from "@astrojs/starlight/components/TableOfContents.astro"; +import InfoPanel from "../InfoPanel.astro"; +--- + + diff --git a/src/content/config.ts b/src/content/config.ts index 45f60b0..c222fc2 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,6 +1,17 @@ -import { defineCollection } from 'astro:content'; +import { defineCollection, z } from 'astro:content'; import { docsSchema } from '@astrojs/starlight/schema'; export const collections = { - docs: defineCollection({ schema: docsSchema() }), + docs: defineCollection({ + schema: docsSchema({ + extend: ({ doc }) => { + return z.object({ + isAEP: z.optional(z.boolean()), + created: z.optional(z.date()), + updated: z.optional(z.date()), + id: z.optional(z.number()), + }); + }, + }) + }), };