--- import Layout from "./Layout.astro"; import VerticalNav from "../components/verticalNav.astro"; type Navigation = Record< string, { title: string; url: string; order: number }[] >; export function formatTitle(title: string): string { return title .split("-") .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(" "); } export async function setup() { // setup navigation const getStartedFiles = await Astro.glob("../pages/get-started/*.md"); const guideFiles = await Astro.glob("../pages/guide/*.md"); const markdownFiles = [...getStartedFiles, ...guideFiles]; const navigation: Navigation = {}; for (const file of markdownFiles) { const filePath = file.url; const [_, category] = filePath!.split("/"); const formattedCategory = formatTitle(category); const formattedTitle = file.frontmatter.title; const order = file.frontmatter.order ?? 0; if (!navigation[formattedCategory]) { navigation[formattedCategory] = []; } navigation[formattedCategory].push({ title: formattedTitle, url: filePath || "", order, }); } // sort by "order" const sortedNavigation: Navigation = {}; Object.keys(navigation) .sort() .forEach((key) => { sortedNavigation[key] = navigation[key].sort( (a, b) => a.order - b.order, ); }); return { navigation: sortedNavigation, }; } const { navigation } = await setup(); ---