Skip to content

Generate sitemap from blog post metadata #92

@KaliCZ

Description

@KaliCZ

Depends on

#91 — blog section with per-post exported metadata.

Problem

Search engines benefit from an accurate sitemap.xml with <lastmod> per URL. The official @astrojs/sitemap integration auto-discovers pages but doesn't know about custom per-post updatedDate metadata, so <lastmod> entries for blog posts would be inaccurate (or missing) without custom handling.

Proposed change

Once #91 lands, every blog post already exports pubDate and updatedDate as part of its metadata contract. That makes tuning the sitemap essentially free: reuse the same import.meta.glob pattern used by /rss.xml, and emit <loc> + <lastmod> per post.

Scope

  • Custom sitemap endpoint at /sitemap.xml (or /blog-sitemap.xml alongside the default) that:
    • Globs blog post files
    • Emits <loc> from the post URL and <lastmod> from updatedDate (falling back to pubDate)
    • Skips drafts
  • Decide between: (a) fully custom sitemap covering all pages, or (b) keep @astrojs/sitemap for static pages and add a separate blog sitemap plus a sitemap index. Option (a) is simpler if page count stays small.
  • Verify output against Google Search Console's sitemap validator.

Why this is easy after #91

The blog system introduced in #91 defines a metadata contract (title, pubDate, updatedDate, draft, …) and a glob-based discovery pattern. The sitemap is just a second consumer of that same contract — the data model is already there, we only add another endpoint that projects it into a different XML shape.

Files

  • frontend/src/pages/sitemap.xml.ts (or blog-sitemap.xml.ts) — new
  • frontend/astro.config.mjs — adjust @astrojs/sitemap config depending on chosen approach

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions