Add trailing slash to paths

This commit is contained in:
Brad Treloar 2025-11-01 21:53:40 +10:30
parent 16808ee943
commit 8efbad5c63

View file

@ -4,7 +4,7 @@ import { getCollection, type CollectionEntry } from "astro:content";
export type Document = CollectionEntry<"docs">;
export function getDocumentPath(document: Document) {
return "/" + document.id.replace(/\/_index$/, "");
return "/" + document.id.replace(/\/_index$/, "") + "/";
}
export function getDocumentTitle(document: Document) {
@ -23,8 +23,8 @@ export async function getChildDocuments(parentDocument: Document | undefined) {
const documents = await getCollection("docs");
const basePath =
parentDocument !== undefined ? getDocumentPath(parentDocument) : "";
const pathPattern = new RegExp(`^${basePath}/[^/]+$`);
parentDocument !== undefined ? getDocumentPath(parentDocument) : "/";
const pathPattern = new RegExp(`^${basePath}[^/]+/$`);
const childDocuments = documents.filter((document) => {
const path = getDocumentPath(document);