diff --git a/src/components/Toc.astro b/src/components/Toc.astro index 39e1389..1345975 100644 --- a/src/components/Toc.astro +++ b/src/components/Toc.astro @@ -10,26 +10,29 @@ }; async function getSectionPages(sectionPath: string): Promise { - const allPages = await Astro.glob("../pages/**/*.mdx"); + const allPages = await import.meta.glob(`../pages/**/*.mdx`); - return allPages - .filter((page) => page.file.includes(`/pages/${sectionPath}/`)) - .map((page) => { - const fileName = page.file.split("/").pop()?.replace(".mdx", "") || ""; - const url = `/${sectionPath}/${fileName}`; + const filteredPages = Object.entries(allPages).filter(([path, _]) => + path.includes(`/pages/${sectionPath}/`), + ); - const [index, titlePart] = fileName.split("-"); - const title = (page as any).title || page.frontmatter?.title || titlePart; + const files = await Promise.all( + filteredPages.map(async ([filePath, resolver]) => { + const module = await resolver(); + return { + file: filePath, + title: module.title || module.frontmatter?.title || "", + url: module.url || "", + }; + }), + ); - return { url, title, order: index }; - }) - .sort((a, b) => a.order - b.order); + return files; } const currentPath = Astro.url.pathname; const sections: Section[] = []; - const sectionPaths = ["html", "js", "cli", "php", "sql", "git", "tips"]; for (const path of sectionPaths) {