Skip to content

feat(build): add --repo-url flag to link the source repo from the site footer - #383

Merged
dubadub merged 1 commit into
mainfrom
feat/repo-link-in-footer
Aug 3, 2026
Merged

dubadub merged 1 commit into
mainfrom
feat/repo-link-in-footer

Conversation

@dubadub

@dubadub dubadub commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds --repo-url <URL> to cook build web
  • When set, the generated site footer's "Built with CookCLI" line gains a "View source" link pointing to the given repository URL, on every page (index, directory listings, recipes, and menus)
  • Validated as an absolute http(s) URL, mirroring the existing --sitemap validation
  • Scoped to cook build web only, matching the issue — the footer link only ever renders in static-site output (static_mode), never in cook server

Fixes #376

Test plan

  • cargo fmt
  • cargo clippy --all-targets -- -D warnings
  • cargo test (full suite, including new tests: link present with --repo-url, absent without it, and invalid URLs are rejected)

…e footer

Static sites generated by `cook build web` had no way to point back
to the recipe repository, so users had to post-process the generated
HTML to add a link (as reported in #376).

Fixes #376
@claude

claude Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review: --repo-url flag for cook build web

Nicely scoped feature — clean, well-documented, and follows the existing --sitemap pattern closely. A few notes:

Strengths

  • Security: --repo-url is validated up front (src/build/mod.rs:144-151) to require an absolute http/https URL with a host, which blocks javascript:/data: schemes and scheme-less/relative values before the string ever reaches the template. Askama also HTML-escapes {{ url }} by default in templates/base.html:884, so this is defense-in-depth rather than the only guard.
  • Scoping: the footer link only ever renders in static_mode (static build output), and src/server/ui.rs explicitly sets repo_url: None for every live-server handler — so the flag can't leak into the dynamic server UI by accident.
  • Docs: README.md and docs/build.md were both updated with consistent examples.
  • Tests: good coverage for a CLI flag — asserts the link is omitted by default, present (and propagated to nested recipe pages, not just the index) when set, and that an invalid URL fails the build with a useful error. This is actually more coverage than the existing --sitemap flag has (no tests for it in tests/build.rs).
  • No new dependencies — reuses the already-present url crate (also used for --sitemap validation).

Minor / non-blocking observations

  • Validation duplication: the --repo-url and --sitemap validation blocks in src/build/mod.rs are nearly identical (parse → check host → check scheme). Given --sitemap's validation also excludes query/fragment (not needed here), a full shared helper isn't a clean fit, but a small fn validate_absolute_http_url(url: &str, flag: &str) -> Result<Url> could remove a few lines of near-duplicate logic if you want to tidy it up.
  • Parameter confusion risk: base_url: Option<&str> and repo_url: Option<&str> are now threaded together through walk_directories/walk_recipes/render_* (7-8 positional params, both same type). This already matches the existing pattern for base_url, so it's not a new anti-pattern introduced by this PR, but it's easy to transpose two same-typed Option<&str> args by accident in a future edit — worth keeping in mind if more of these get added later (e.g. a small options struct).
  • Only tested the "unparseable" invalid-URL case (not-a-url); an explicit test for the "parses fine but wrong scheme" branch (e.g. ftp://example.com or mailto:[email protected]) would pin down that second guard condition too, though it's low risk since the logic is straightforward.

Overall this looks safe and ready to merge as-is; the observations above are polish, not blockers.

@dubadub
dubadub merged commit 8b0121f into main Aug 3, 2026
6 checks passed
@dubadub
dubadub deleted the feat/repo-link-in-footer branch August 3, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add link to repository

1 participant