Repository navigation
feat: Atom and RSS feeds for cook build web and cook server - #521
Merged
Merged
Conversation
`cook build web --feed <URL>` writes atom.xml and rss.xml at the output root with one item per recipe and menu page, newest first. Items take their title, date, description, author and tags from recipe metadata; the date falls back to the file's modification time. Closes cooklang#503 Co-Authored-By: Claude Opus 5 <[email protected]>
LeMyst
marked this pull request as draft
September 21, 2026 18:19
`cook server` now renders the recipe feeds on each request, with links to its own /recipe/ pages. Absolute URLs come from the Host header and --url-prefix (X-Forwarded-Proto: https switches the scheme); the title and language follow Accept-Language. Every page advertises both feeds with <link rel="alternate"> for feed-reader autodiscovery. The feed module now takes a PageUrls mode so the static build and the server share the same item collection and rendering. Co-Authored-By: Claude Opus 5 <[email protected]>
The feed and the sitemap almost always describe the same site, so `--feed` alone now takes its URL from --sitemap. An explicit URL is passed as `--feed=URL`; the `=` is required so `--feed out` keeps `out` as the output directory. A URL-looking output directory is rejected with a hint, catching `--feed https://...` typed with a space. Co-Authored-By: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #503
Summary
Web feeds (Atom 1.0 and RSS 2.0), one item per recipe and menu, newest first, in both places recipes are published:
cook build web --feed[=<URL>]writesatom.xmlandrss.xmlat the static site's output root.cook serverserves/atom.xmland/rss.xml, rendered from the recipe files on each request, so they are always up to date. Every page advertises both with<link rel="alternate">so feed readers can discover them from the site's address.Each item takes these fields from recipe metadata:
titledate(YYYY-MM-DDor RFC 3339)descriptionauthor/author.name/source.author<author>, RSS<dc:creator>)tagsThe feed title is the localized "All Recipes" heading. It follows
--langfor the static build andAccept-Languagefor the server.Static build (
--feed)--feedalone reuses the--sitemapURL (cook build web --sitemap https://x --feed).--feed=<URL>sets it explicitly. Either way it is independent of--base-url.--sitemapitself is unchanged.=is required (require_equals), so--feed outkeepsoutas the output directory. An output directory containing://is rejected with a hint to use--feed=<URL>, catching--feed https://...typed with a space.updated/lastBuildDateis its newest item's date, not the time of the build. An unchanged recipe set therefore produces an identical file.--compressruns, so they get.gzcopies too.Server (
/atom.xml,/rss.xml)/recipe/<path>pages. Their absolute base comes from the request'sHost(or the HTTP/2 authority) plus--url-prefix, via the existingcors::request_authority.X-Forwarded-Hostis ignored, consistent with the same-origin check.X-Forwarded-Proto: httpsis honoured for the scheme only, so TLS-terminating proxies gethttps://links; it can only affect the response sent back to the same client.Hostthat would inject a path, query, fragment or credentials into the links is rejected with 400.spawn_blocking.Implementation notes
src/build/feed.rsholds the shared collection and rendering. APageUrlsmode (Static { output }/Server) decides each item's page path and whether it is listed.xml_escapeandbuild_locfromsitemap.rsare reused.xml_escapenow also escapes", because the feeds put values in attributes (href,term).--sitemapURL check is now a sharedvalidate_site_urlhelper.web::i18nis nowpub(crate)so the feed title can be localized.Test plan
tests/build.rs: feeds written with--feed=URL, absent without it, relative URL rejected;--feedalone reuses--sitemap, fails without it; explicit URL overrides--sitemap; URL-looking output dir rejectedtests/server_feed_test.rs: Atom and RSS responses and content types, absolute links,--url-prefix+X-Forwarded-Proto,Accept-Language, autodiscovery tags--feed --lang fr-FR(both files are valid XML); rancook server seedand checked that all 14 feed links return 200, menus includedcargo fmt,cargo clippy --all-targets,cargo testall clean🤖 Generated with Claude Code