website

Personal website
git clone https://git.michaelneuper.com/website.git
README | Files | Log | Refs

commit d6843c5383f61fbc586deb5a4f7cb9e1253ff489
parent ff83e86f0bc0c422ce4f332de7bfe30e5644a2ce
Author: Michael Neuper <michael@michaelneuper.com>
Date:   Wed, 28 Oct 2026 10:43:20 +0200

add sitemap

Diffstat:
MREADME.md | 2+-
Mpublic/robots.txt | 2++
Asrc/pages/sitemap.xml.js | 16++++++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md @@ -20,7 +20,7 @@ npm run preview # serves dist/ at http://localhost:4321 | Path | What it is | |----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------| -| `src/pages/` | the pages: home, `posts/[slug]` for every post, 404, the RSS feeds and the giscus themes | +| `src/pages/` | the pages: home, `posts/[slug]` for every post, 404, the RSS feeds, the sitemap and the giscus themes | | `src/layouts/Base.astro` | the frame every page shares | | `src/components/frame/` | the Emacs around each page: top line, modeline, `*Help*`, and `Buffer`, a section with its winbar | | `src/components/home/` | the home page's sections: hero (my name in front of a wall of my C), about, projects, posts, contact, and the coffee | diff --git a/public/robots.txt b/public/robots.txt @@ -1,3 +1,5 @@ User-agent: * Allow: / Disallow: /notes-to-self.txt + +Sitemap: https://michaelneuper.com/sitemap.xml diff --git a/src/pages/sitemap.xml.js b/src/pages/sitemap.xml.js @@ -0,0 +1,16 @@ +// The sitemap for search engines: the home page and every published post. The +// Hugo site had one at /sitemap.xml, so Search Console may already know this +// address. Drafts stay out, as they do everywhere else. + +import { publishedPosts } from "../lib/posts.js"; + +export async function GET({ site }) { + const posts = await publishedPosts(); + const urls = ["/", ...posts.map((p) => `/posts/${p.id}/`)].map((path) => ` <url><loc>${new URL(path, site)}</loc></url>`); + const xml = `<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> +${urls.join("\n")} +</urlset> +`; + return new Response(xml, { headers: { "Content-Type": "application/xml; charset=utf-8" } }); +}