Skip to content

fix(web): link the source name for nested and flat source metadata - #853

Merged
dubadub merged 1 commit into
cooklang:mainfrom
jjohnnystwsss:fix/848-source-metadata
Nov 24, 2026
Merged

dubadub merged 1 commit into
cooklang:mainfrom
jjohnnystwsss:fix/848-source-metadata

Conversation

@jjohnnystwsss

Copy link
Copy Markdown
Contributor

Closes #848

What changes

source metadata now renders the same way in every form, on recipe and menu pages and in both server and static mode:

Metadata Before After
source: with nested name and url nothing shown one pill: the name, linked to the URL
source.name + source.url two pills (the name, and a separate 🔗 hostname link) one pill: the name, linked to the URL
only a name, or only a URL name as text / hostname link unchanged
plain source: Some book or source: https://… text / hostname link unchanged
  • src/web/builders.rs: a small source_metadata helper reads source with cooklang's as_name_and_url (so the nested mapping, a plain string and Name <url> are all handled by the parser), then falls back to the flat source.name / source.url keys. Recipes and menus both use it. Menus now skip source.* keys in the custom metadata pills, as recipes already did.
  • templates/source_metadata.html: the shared source pill, included by recipe.html and menu.html in place of the two duplicated blocks. Askama escapes the name, and the existing is_web_url filter decides whether the URL becomes a link, so a javascript: URL stays plain text.

Tests

  • tests/source_metadata_test.rs: 5 tests that build real recipe and menu pages (server and static mode) from metadata and check the rendered pill: nested, flat, name only, URL only, plain text / plain URL, and escaping (an <img onerror> tag as the name, a javascript: URL), for both the nested and the flat form.
    • Without the fix: 4 fail, 1 passes (the plain text / plain URL case, which keeps the existing behaviour).
    • With the fix: 5 pass, with default features and with --no-default-features.
  • On macOS (Rust 1.100): cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace (1909 passed, 0 failed) and cargo test --no-default-features (491 passed, 0 failed).

I didn't add a CHANGELOG entry, since release-please builds it from the commit message.

This was implemented with OpenAI Codex, then reviewed and re-tested with Claude Code.

🤖 Generated with Claude Code

A nested `source: { name, url }` block was not rendered at all, and the
flat `source.name` / `source.url` keys showed up as two separate pills.
Both forms now go through the cooklang metadata parser, like a plain
`source` value, and render one source pill with the name linked to the
URL. Menus no longer repeat `source.*` keys as custom metadata. Names
are HTML-escaped and URLs that are not http(s) are never links.

Closes cooklang#848

Co-authored-by: Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dubadub

dubadub commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks, this is a clean fix. The flat source.name / source.url fallback really belongs in the parser, since conventions.md lists those keys as canonical. I've opened cooklang/cooklang-rs#159 so Metadata::source() (and author() with source.author) handle them for every app. This PR doesn't need to wait for it: once that's released, the fallback in source_metadata can be dropped in a follow-up.

@jjohnnystwsss

Copy link
Copy Markdown
Contributor Author

Thanks! Agreed, the parser is the right place for it. Once cooklang-rs#159 is released, I'm happy to open the follow-up that drops the fallback in source_metadata.

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.

source block with name and url does not get rendered

2 participants