enable page creation in the CMS (create: true) + dynamic nav (import.meta.glob over src/pages)
This commit is contained in:
1 parent
3ac81d5a52
commit
95af7107d0
3 files changed
+14
-8
No files matched your search
+10
-4
@@ -1,8 +1,14 @@
|
||||
---
|
||||
const pages = [
|
||||
{ href: "/", label: "Home" },
|
||||
{ href: "/about", label: "About" },
|
||||
];
|
||||
const pageFiles = import.meta.glob("../pages/**/*.md", { eager: true });
|
||||
const pages = Object.entries(pageFiles)
|
||||
.map(([file, mod]) => {
|
||||
const slug = file.replace("../pages", "").replace(/\.md$/, "");
|
||||
return {
|
||||
href: slug === "/index" ? "/" : slug,
|
||||
label: mod.frontmatter?.title ?? slug,
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a.href.localeCompare(b.href));
|
||||
// Markdown pages hand their frontmatter to the layout as `frontmatter`.
|
||||
const { title } = Astro.props.frontmatter ?? Astro.props;
|
||||
---
|
||||
|
||||
Reference in new issue
Block a user