Skip to content

feat: Atom and RSS feeds for cook build web and cook server - #521

Merged
dubadub merged 3 commits into
cooklang:mainfrom
LeMyst:feat/web-feeds
Sep 22, 2026
Merged

dubadub merged 3 commits into
cooklang:mainfrom
LeMyst:feat/web-feeds

Conversation

@LeMyst

@LeMyst LeMyst commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

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>] writes atom.xml and rss.xml at the static site's output root.
  • cook server serves /atom.xml and /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:

Field Feed use
title Item title (falls back to the file name)
date (YYYY-MM-DD or RFC 3339) Item date. Without it, the file's modification time is used.
description Summary
author / author.name / source.author Author (Atom <author>, RSS <dc:creator>)
tags Categories

The feed title is the localized "All Recipes" heading. It follows --lang for the static build and Accept-Language for the server.

Static build (--feed)

  • Feeds need absolute links, so they need the site's full URL. It is almost always the sitemap's, so --feed alone reuses the --sitemap URL (cook build web --sitemap https://x --feed). --feed=<URL> sets it explicitly. Either way it is independent of --base-url. --sitemap itself is unchanged.
  • The = is required (require_equals), so --feed out keeps out as the output directory. An output directory containing :// is rejected with a hint to use --feed=<URL>, catching --feed https://... typed with a space.
  • Only pages that were actually written are listed, so recipes that fail to render never become dead links.
  • The feed's own updated/lastBuildDate is its newest item's date, not the time of the build. An unchanged recipe set therefore produces an identical file.
  • The feeds are written before --compress runs, so they get .gz copies too.

Server (/atom.xml, /rss.xml)

  • Links point to the server's /recipe/<path> pages. Their absolute base comes from the request's Host (or the HTTP/2 authority) plus --url-prefix, via the existing cors::request_authority.
  • X-Forwarded-Host is ignored, consistent with the same-origin check. X-Forwarded-Proto: https is honoured for the scheme only, so TLS-terminating proxies get https:// links; it can only affect the response sent back to the same client.
  • A Host that would inject a path, query, fragment or credentials into the links is rejected with 400.
  • The tree walk runs in spawn_blocking.

Implementation notes

  • src/build/feed.rs holds the shared collection and rendering. A PageUrls mode (Static { output } / Server) decides each item's page path and whether it is listed.
  • xml_escape and build_loc from sitemap.rs are reused. xml_escape now also escapes ", because the feeds put values in attributes (href, term).
  • The --sitemap URL check is now a shared validate_site_url helper.
  • web::i18n is now pub(crate) so the feed title can be localized.

Test plan

  • Unit tests: date parsing, metadata vs mtime, filtering/sorting, static and server URL modes, Atom/RSS rendering, escaping, empty feed, server base URL (host + prefix, forwarded proto, rejected hosts)
  • tests/build.rs: feeds written with --feed=URL, absent without it, relative URL rejected; --feed alone reuses --sitemap, fails without it; explicit URL overrides --sitemap; URL-looking output dir rejected
  • tests/server_feed_test.rs: Atom and RSS responses and content types, absolute links, --url-prefix + X-Forwarded-Proto, Accept-Language, autodiscovery tags
  • Manual: built the seed collection with --feed --lang fr-FR (both files are valid XML); ran cook server seed and checked that all 14 feed links return 200, menus included
  • cargo fmt, cargo clippy --all-targets, cargo test all clean

🤖 Generated with Claude Code

`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
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]>
@LeMyst LeMyst changed the title feat(build): generate Atom and RSS feeds with --feed feat: Atom and RSS feeds for cook build web and cook server Sep 21, 2026
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]>
@LeMyst
LeMyst marked this pull request as ready for review September 22, 2026 17:04
@dubadub
dubadub merged commit 4307018 into cooklang:main Sep 22, 2026
6 checks passed
@LeMyst
LeMyst deleted the feat/web-feeds branch September 23, 2026 18:18
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.

[Feature Request] Web Feed

2 participants