From 95af7107d08c6b7c0945eaa23b58cb49cf557e7a Mon Sep 17 00:00:00 2001 From: Keith Date: Sat, 21 Nov 2026 08:32:35 +0100 Subject: [PATCH] enable page creation in the CMS (create: true) + dynamic nav (import.meta.glob over src/pages) --- dist/admin/config.yml | 4 ++-- public/admin/config.yml | 4 ++-- src/layouts/Site.astro | 14 ++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dist/admin/config.yml b/dist/admin/config.yml index 4afd370..bae4571 100644 --- a/dist/admin/config.yml +++ b/dist/admin/config.yml @@ -31,8 +31,8 @@ collections: folder: /src/pages extension: md format: yaml-frontmatter - create: false # the fixed page set; the site nav is static - delete: false # removing a page would break the nav mid-build + create: true # pages land in src/pages and appear in the nav (it is built from this folder) + delete: false # a page (the Home page above all) cannot be deleted from the CMS slug: "{{slug}}" identifier_field: title summary: "{{title}}" diff --git a/public/admin/config.yml b/public/admin/config.yml index 4afd370..bae4571 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -31,8 +31,8 @@ collections: folder: /src/pages extension: md format: yaml-frontmatter - create: false # the fixed page set; the site nav is static - delete: false # removing a page would break the nav mid-build + create: true # pages land in src/pages and appear in the nav (it is built from this folder) + delete: false # a page (the Home page above all) cannot be deleted from the CMS slug: "{{slug}}" identifier_field: title summary: "{{title}}" diff --git a/src/layouts/Site.astro b/src/layouts/Site.astro index a4393be..99d0671 100644 --- a/src/layouts/Site.astro +++ b/src/layouts/Site.astro @@ -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; ---