From 7059ad771a42a81ac154393e51f052e6b8369330 Mon Sep 17 00:00:00 2001 From: kodster28 Date: Mon, 10 Mar 2025 13:19:29 -0500 Subject: [PATCH 1/5] [Docs Site] Add tags to bottom of pages --- src/components/PageTags.astro | 39 +++++++++++++++++++ src/components/index.ts | 1 + src/components/overrides/Footer.astro | 6 +++ .../docs/workers/examples/alter-headers.mdx | 3 +- src/schemas/base.ts | 7 +++- src/schemas/tags.ts | 7 ++++ 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/components/PageTags.astro create mode 100644 src/schemas/tags.ts diff --git a/src/components/PageTags.astro b/src/components/PageTags.astro new file mode 100644 index 00000000000000..5b899b83fa98b6 --- /dev/null +++ b/src/components/PageTags.astro @@ -0,0 +1,39 @@ +--- +import { z } from "astro:schema"; +import { Badge } from "@astrojs/starlight/components"; +import { componentToString } from "~/util/container"; +import { tagsValues } from "~/schemas/tags"; + +type Props = z.infer; + +const props = z.object({ + tags: z.enum(tagsValues).array().optional(), +}); + +const parsedValues = props.safeParse(Astro.props); +let tagPlaceholder: Array; + +if (!parsedValues.success) { + // handle error then return + tagPlaceholder = []; +} else { + // do something + tagPlaceholder = parsedValues.data.tags; +} + +const tags = tagPlaceholder; +console.log(tagPlaceholder); +console.log(parsedValues); +--- + +{ + tags && ( +
+ {tags.map((tag) => ( + + + + ))} +
+ ) +} diff --git a/src/components/index.ts b/src/components/index.ts index 49d8392bd9d73a..7ed800f3c2de87 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -39,6 +39,7 @@ export { default as PagesBuildEnvironmentTools } from "./PagesBuildEnvironmentTo export { default as PagesBuildPreset } from "./PagesBuildPreset.astro"; export { default as PagesBuildPresetsTable } from "./PagesBuildPresetsTable.astro"; export { default as PagesLanguageSupport } from "./PagesLanguageSupport.astro"; +export { default as PageTags } from "./PageTags.astro"; export { default as Plan } from "./Plan.astro"; export { default as PlanInfo } from "./PlanInfo.astro"; export { default as ProductReleaseNotes } from "./ProductReleaseNotes.astro"; diff --git a/src/components/overrides/Footer.astro b/src/components/overrides/Footer.astro index de57c5dbf882bb..7126c2c0de8e07 100644 --- a/src/components/overrides/Footer.astro +++ b/src/components/overrides/Footer.astro @@ -2,6 +2,7 @@ import Default from "@astrojs/starlight/components/Footer.astro"; import OneTrust from "../OneTrust.astro"; import FeedbackPrompt from "../FeedbackPrompt.tsx"; +import PageTags from "~/components/PageTags.astro"; import { getEntry } from "astro:content"; let links = { @@ -24,6 +25,9 @@ if (currentSection) { } } +const frontmatter = Astro.locals.starlightRoute.entry.data; +const tags = frontmatter.tags; + const homepageLinks = Object.entries({ Resources: [ { text: "API", href: "/api/" }, @@ -128,6 +132,8 @@ if ( +
+ {tags && }