Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/content.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ const issue = z.object({
url: z.string(),
});

// Slugs handed out so far, by post directory. Two posts with one slug would
// silently overwrite each other, so a repeat fails the build instead.
const blogSlugs = new Map<string, string>();

const blog = defineCollection({
// Slug = kebab-cased title, as on the Gatsby site (/blog/<slug>).
loader: glob({
base: "./blog",
pattern: "*/index.md",
generateId: ({ data }) => kebabCase(String(data.title)),
generateId: ({ entry, data }) => {
const slug = kebabCase(String(data.title));
for (const [other, taken] of blogSlugs) {
if (taken === slug && other !== entry) {
throw new Error(
`Blog posts ${other} and ${entry} both map to /blog/${slug}; retitle one.`,
);
}
}
blogSlugs.set(entry, slug);
return slug;
},
}),
schema: ({ image }) =>
z.object({
Expand Down
Loading