Repository navigation
feat(build): generate sitemap.xml with cook build web --sitemap - #351
Conversation
Adds a `--sitemap <URL>` flag to `cook build web`. When provided, walks the pruned RecipeTree to collect homepage, directory, and recipe/menu page entries (with best-effort mtime lastmod), renders a sitemaps.org-compliant sitemap.xml, and writes it to the output root. The URL is validated with the `url` crate before use.
…agment Address final review: guard recipe/menu entries by on-disk existence so recipes the render pass skipped don't become dead links; sort entries for deterministic output; reject --sitemap URLs carrying a query or fragment.
Code ReviewGood, focused feature. The module structure mirrors Medium: URL validated too late — The Minor: directory pages skip the on-disk existence check — Recipe/menu leaves are gated by Minor:
Low: docs/superpowers/ files should not be committed
Nit: timezone-sensitive
Nit: tree-walk logic untested The 7 unit tests cover all pure rendering helpers well. The Already good
|
- Validate --sitemap URL up front in run_web so typos fail before the full build runs, instead of after. - Guard directory page entries with the same on-disk existence check as recipe/menu pages (still recurse so child recipes are unaffected). - Use UTC for <lastmod> so dates are reproducible across machines. - Add a tree-walk test covering stem extraction, existence filtering, and deterministic sorting.
|
Thanks for the review! Addressed in 9dbcd93:
One point I looked into but did not change:
On the docs/superpowers/ files: keeping them to stay consistent with the existing convention (there are already 4 spec files under |
|
---\n## Code Review — PR #351: |
Code Review — PR #351:
|
| Category | Status |
|---|---|
| Core logic | Correct |
| Edge cases (missing pages, bad mtime) | Handled |
| URL encoding + XML escaping | Correct |
| Test coverage | Good |
| Cargo.toml deps declared | Unverified |
child.path for leaf lastmod |
Verify |
| Docs artifacts in repo | Should be removed |
The implementation is solid. The main requests before merging: drop the docs/superpowers/ planning files and confirm urlencoding, url, and tempfile are declared in Cargo.toml.
|
thanks ! I will test on the next release =D |
cookcli 0.31.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## [0.31.0](cooklang/cookcli@v0.30.0...v0.31.0) (2026-06-09) ### Features * **build:** generate sitemap.xml with `cook build web --sitemap` ([#351](cooklang/cookcli#351)) ([6db127a](cooklang/cookcli@6db127a)) ### Bug Fixes * **server:** avoid renameat2 SIGSYS on aarch64 Android (Termux) ([#353](cooklang/cookcli#353)) ([46950ab](cooklang/cookcli@46950ab)), closes [#349](https://github.com/cooklang/cookcli/issues/349)</pre> <p>View the full release notes at <a href="https://github.com/cooklang/cookcli/releases/tag/v0.31.0">https://github.com/cooklang/cookcli/releases/tag/v0.31.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!11090
Summary
Closes #346. Adds optional sitemap generation to the
cook build webstatic-site generator.--sitemap <URL>flag. When given the deployed site's full base URL (e.g.https://recipes.example.comorhttps://example.com/recipes), it writes a sitemaps.org-compliantsitemap.xmlat the output root. Omitting it preserves existing behavior (no sitemap).<base>/), every directory listing page, and every recipe/menu page as absolute URLs, with path segments percent-encoded and a best-effort<lastmod>from each source file's modification time.--base-url(which only controls internal link prefixes);--sitemapcarries scheme + host + optional subpath.Robustness
http(s)URL with a host and no query/fragment, else a clear error and non-zero exit.Implementation
src/build/sitemap.rs: pure, unit-tested rendering helpers (xml_escape,encode_path,build_loc,format_lastmod,render_sitemap_xml) plus tree-walk glue mirroring the existingindex.rspattern.src/build/mod.rs: the--sitemapflag onWebBuildArgs, URL validation, and the write call inrun_web(reusing the already-pruned recipe tree).Design/plan docs:
docs/superpowers/specs/2026-06-06-sitemap-static-site-design.md,docs/superpowers/plans/2026-06-06-sitemap-static-site.md.Test Plan
cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo testall pass (7 new sitemap unit tests)cook build web /tmp/site --base-path ./seed --sitemap https://recipes.example.comwritessitemap.xml; summary line notes itxmllint --noout) and every<loc>maps to a real generated file--sitemapproduces no sitemap--sitemapURLs are rejected with exit code 1sitemap.xml(deterministic)