Skip to content
Merged
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
24 changes: 16 additions & 8 deletions src/pages/docs/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ import { getOrderedDocs, docHref, sidebarLabel } from "../../lib/docs-nav";

export async function getStaticPaths() {
const docs = await getOrderedDocs();
return docs.map((doc, index) => ({
params: { slug: doc.id },
props: {
doc,
prev: index > 0 ? docs[index - 1] : null,
next: index < docs.length - 1 ? docs[index + 1] : null,
},
}));
return docs.map((doc, index) => {
// A `next:` frontmatter slug overrides the sequence order.
const override = doc.data.next;
const nextDoc = override ? docs.find((entry) => entry.id === override) : undefined;
if (override && !nextDoc) {
throw new Error(`docs/${doc.id}: next "${override}" does not match any doc`);
}
return {
params: { slug: doc.id },
props: {
doc,
prev: index > 0 ? docs[index - 1] : null,
next: nextDoc ?? (index < docs.length - 1 ? docs[index + 1] : null),
},
};
});
}

type Props = InferGetStaticPropsType<typeof getStaticPaths>;
Expand Down
Loading