Skip to content

Commit 7059ad7

Browse files
committed
[Docs Site] Add tags to bottom of pages
1 parent 0c69911 commit 7059ad7

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

src/components/PageTags.astro

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { Badge } from "@astrojs/starlight/components";
4+
import { componentToString } from "~/util/container";
5+
import { tagsValues } from "~/schemas/tags";
6+
7+
type Props = z.infer<typeof props>;
8+
9+
const props = z.object({
10+
tags: z.enum(tagsValues).array().optional(),
11+
});
12+
13+
const parsedValues = props.safeParse(Astro.props);
14+
let tagPlaceholder: Array<String>;
15+
16+
if (!parsedValues.success) {
17+
// handle error then return
18+
tagPlaceholder = [];
19+
} else {
20+
// do something
21+
tagPlaceholder = parsedValues.data.tags;
22+
}
23+
24+
const tags = tagPlaceholder;
25+
console.log(tagPlaceholder);
26+
console.log(parsedValues);
27+
---
28+
29+
{
30+
tags && (
31+
<div class="flex flex-row gap-2">
32+
{tags.map((tag) => (
33+
<a href={`/search/?tag=${tag}`} class="no-underline">
34+
<Badge text={tag} variant="tip" />
35+
</a>
36+
))}
37+
</div>
38+
)
39+
}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export { default as PagesBuildEnvironmentTools } from "./PagesBuildEnvironmentTo
3939
export { default as PagesBuildPreset } from "./PagesBuildPreset.astro";
4040
export { default as PagesBuildPresetsTable } from "./PagesBuildPresetsTable.astro";
4141
export { default as PagesLanguageSupport } from "./PagesLanguageSupport.astro";
42+
export { default as PageTags } from "./PageTags.astro";
4243
export { default as Plan } from "./Plan.astro";
4344
export { default as PlanInfo } from "./PlanInfo.astro";
4445
export { default as ProductReleaseNotes } from "./ProductReleaseNotes.astro";

src/components/overrides/Footer.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Default from "@astrojs/starlight/components/Footer.astro";
33
import OneTrust from "../OneTrust.astro";
44
import FeedbackPrompt from "../FeedbackPrompt.tsx";
5+
import PageTags from "~/components/PageTags.astro";
56
import { getEntry } from "astro:content";
67
78
let links = {
@@ -24,6 +25,9 @@ if (currentSection) {
2425
}
2526
}
2627
28+
const frontmatter = Astro.locals.starlightRoute.entry.data;
29+
const tags = frontmatter.tags;
30+
2731
const homepageLinks = Object.entries({
2832
Resources: [
2933
{ text: "API", href: "/api/" },
@@ -128,6 +132,8 @@ if (
128132
<FeedbackPrompt client:idle />
129133
</div>
130134
<Default />
135+
<br />
136+
{tags && <PageTags tags={tags} />}
131137
<div id="footer-links" class="mt-6 flex flex-wrap items-center space-x-4">
132138
{Object.entries(links).map(([text, href]) => (
133139
<a href={href} class="text-xs text-black decoration-accent">

src/content/docs/workers/examples/alter-headers.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ summary: Example of how to add, change, or delete headers sent in a request or
44
returned in a response.
55
tags:
66
- Headers
7-
- Middleware
7+
- Cookies
8+
- TEST
89
languages:
910
- JavaScript
1011
- TypeScript

src/schemas/base.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { z } from "astro:schema";
22
import { BadgeConfigSchema } from "./types/badge";
33
import type { SchemaContext } from "astro:content";
4+
import { tagsValues } from "./tags";
45

56
const spotlightAuthorDetails = z
67
.object({
@@ -44,7 +45,11 @@ export const baseSchema = ({ image }: SchemaContext) =>
4445
"Refer to https://developers.cloudflare.com/style-guide/documentation-content-strategy/content-types/.",
4546
),
4647
content_type: z.string().optional(),
47-
tags: z.string().array().optional(),
48+
tags: z
49+
.enum(tagsValues)
50+
.array()
51+
.optional()
52+
.catch((ctx) => ctx.input),
4853
external_link: z
4954
.string()
5055
.optional()

src/schemas/tags.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const tagsValues = [
2+
"Cookies",
3+
"GraphQL",
4+
"Headers",
5+
"mTLS",
6+
"Redirects",
7+
] as const;

0 commit comments

Comments
 (0)