Skip to content

Commit 248e701

Browse files
committed
Update logic to account for removed tags
1 parent d9ed0d0 commit 248e701

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

src/components/PageTags.astro

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,20 @@ import { tagsValues } from "~/schemas/tags";
77
type Props = z.infer<typeof props>;
88
99
const props = z.object({
10-
tags: z
11-
.array(z.string())
12-
.optional()
13-
.transform((tags) => {
14-
if (tags) {
15-
// Only keep values that are in tagsValues
16-
return tags.filter((tag) => tagsValues.includes(tag));
17-
}
18-
return [];
19-
}),
10+
tags: z.array(z.string()).transform((tags) => {
11+
if (tags) {
12+
// Only keep values that are in tagsValues
13+
return tags.filter((tag) => tagsValues.includes(tag));
14+
}
15+
return [];
16+
}),
2017
});
2118
2219
const { tags } = props.parse(Astro.props);
2320
---
2421

2522
{
26-
tags && (
23+
tags && tags?.length > 0 && (
2724
<div class="flex flex-row gap-2">
2825
<strong>Page tags:</strong>
2926
{tags.map((tag) => (

src/components/overrides/Head.astro

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,26 @@ if (Astro.locals.starlightRoute.entry.data.tags) {
143143
type Props = z.infer<typeof props>;
144144
145145
const props = z.object({
146-
tags: z
147-
.array(z.string())
148-
.optional()
149-
.transform((tags) => {
150-
if (tags) {
151-
// Only keep values that are in tagsValues
152-
return tags.filter((tag) => tagsValues.includes(tag));
153-
}
154-
return [];
155-
}),
146+
tags: z.array(z.string()).transform((tags) => {
147+
if (tags) {
148+
// Only keep values that are in tagsValues
149+
return tags.filter((tag) => tagsValues.includes(tag));
150+
}
151+
return [];
152+
}),
156153
});
157154
158155
const { tags } = props.parse(Astro.locals.starlightRoute.entry.data);
159-
head.push({
160-
tag: "meta",
161-
attrs: {
162-
name: "pcx_tags",
163-
content: tags.toString(),
164-
},
165-
content: "",
166-
});
156+
if (tags.length > 0) {
157+
head.push({
158+
tag: "meta",
159+
attrs: {
160+
name: "pcx_tags",
161+
content: tags.toString(),
162+
},
163+
content: "",
164+
});
165+
}
167166
}
168167
169168
if (Astro.locals.starlightRoute.entry.data.updated) {

0 commit comments

Comments
 (0)