feat: generate sitemap.xml at build time#35
Conversation
- Add internal/builder/sitemap.go: writes a standard sitemap.xml (sitemaps.org schema 0.9) containing all non-draft pages - Skip silently when [site] base_url is not configured - Hook writeSitemap into Build() as Pass 4, after search-index.json - Add <link rel="sitemap" href="/sitemap.xml"> to layout.html <head> Closes engineervix#4
There was a problem hiding this comment.
Pull request overview
This PR adds build-time generation of a standards-based sitemap.xml to the site output, and exposes it in rendered pages so search engines can discover and index all non-draft documentation pages.
Changes:
- Add
internal/builder/sitemap.goto generate and writeoutput_dir/sitemap.xmlusing the sitemaps.org schema. - Hook sitemap generation into
kwelea buildafter the search index is written. - Add a
<link rel="sitemap" ...>tag to the HTML layout<head>.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| templates/layout.html | Adds a sitemap <link> tag pointing at {{.Site.BasePath}}/sitemap.xml. |
| internal/builder/sitemap.go | Implements sitemap XML generation from site.Pages and writes sitemap.xml to the output directory. |
| internal/builder/builder.go | Invokes writeSitemap() as an additional build pass after search-index.json. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Replace empty-string check with hasScheme() — skip sitemap when base_url is missing or relative (e.g. '/kwelea'), per the sitemaps.org requirement that <loc> entries must be absolute URLs - Add sitemap_test.go: TestHasScheme, TestWriteSitemap (4 sub-tests covering https, trailing slash, empty, relative), TestWriteSitemapExcludesDrafts Addresses Copilot review feedback on PR engineervix#35
|
Good catch 👍 — fixed in 5defcdb.
Also added tests covering this case ( |
- hasScheme now rejects scheme-only strings like 'https://' or 'https:///' (no host component) so writeSitemap won't produce invalid <loc> values - Update Pass 4 comment in builder.go to reflect both skip conditions - Add test cases for https://, http://, and https:/// edge cases Addresses Copilot review feedback round 2 on PR engineervix#35
|
Both points addressed in cd9f347: 1. 2. Updated Pass 4 comment in |
Summary
Generate a standard
sitemap.xmlinoutput_dirduringkwelea build, helping search engines discover and index all pages.Changes
internal/builder/sitemap.go(new) — Writes a standard XML sitemap using the sitemaps.org schema 0.9. Each<url>entry contains a<loc>with the full URL (base_url + page path). Draft pages are excluded.internal/builder/builder.go— HookwriteSitemap()intoBuild()as Pass 4, aftersearch-index.json.templates/layout.html— Add<link rel="sitemap" type="application/xml" href="/sitemap.xml">to<head>.Behaviour
[site] base_urlis set:sitemap.xmlis written tooutput_dir/sitemap.xmlwith all non-draft pages listed.base_urlis not set: sitemap generation is skipped silently (no error, no warning).WalkDocs) do not appear in the sitemap. A defensivepage.Draftcheck is included as well.Verification
Confirmed
<link rel="sitemap" ...>appears in rendered HTML:Closes #4