Every ingredient page on Munchable has two strings that look like they should be one. There is the name a person reads, and there is the segment in the address bar. For most pages they agree. For a few they cannot, and the way we handle those is a good example of treating a URL as a public commitment.
Open munchable.app/is-brewer-s-yeast-gluten-free. The tab title says "Is brewer's yeast gluten free?" with a proper apostrophe. The address says brewer-s-yeast. Both are correct, on purpose.
Where the hyphen comes from
The underlying identifier for an ingredient is a lowercase id with words joined by hyphens, because an id cannot hold an apostrophe. So "brewer's yeast" is stored as brewer-s-yeast. The page generator originally derived the display name from the id by replacing hyphens with spaces and capitalising the first letter, which published the heading as "Brewer s yeast".
The fix is not to change the id. The id is the URL, and the URL is already out in the world: indexed, linked, possibly bookmarked. Changing it means a redirect, a canonical to keep consistent, and a window where the old and new address compete.
So the name and the slug are two functions with two jobs:
const DISPLAY_NAMES: Record<string, string> = { 'en:brewer-s-yeast': "Brewer's yeast", 'en:wheat-fiber': 'Wheat fibre', }; export function displayName(tag: string): string { const named = DISPLAY_NAMES[tag]; if (named) return named; /* otherwise derive from the id */ } function slugFor(tag: string): string { /* the id, with the language prefix removed */ } The override table only names entries whose derived name is wrong. Everything else falls through to the mechanical version, so the table stays small and every row in it is a decision somebody made.
The second kind of mismatch: spelling
The same table fixes a different problem. The shared vocabulary spells one word the American way, fiber, and a British label or a British reader writes fibre. The override puts "fibre" on the page, and the slug keeps the spelling it was published with.
The comment above the table says it directly: the slug is left exactly as it is in both cases, because it is a URL that is already published. Display text is allowed to improve. Addresses are not.
Additives get a third rule
Ingredients that go by a number are the opposite case. For those, the slug is derived from the substance name rather than the id, lowercased and reduced to letters, digits and single hyphens, so the address reads as a word and not as a code. The number is kept for the page itself, where it appears as an alias, because that is how it is printed on a pack.
Three rules for three situations, none of them applied by hand per page.
The test that pins it
A unit test holds the line:
it('names an ingredient the way a label prints it, apostrophes and all', () => { const entry = INGREDIENTS.find((i) => i.tag === 'en:brewer-s-yeast'); assert.equal(entry?.name, "Brewer's yeast"); // The slug is a published URL and must not follow the name. assert.equal(entry?.slug, 'brewer-s-yeast'); }); Two assertions, and the comment between them is the point. A future change that "tidies" the generator so the slug follows the corrected name would pass every other test and break a URL silently. This test fails first, with the reason written next to it.
The metadata has to follow the name, not the slug
One more place this shows up. In the page source the title is HTML escaped, so the apostrophe appears as '. That is the framework doing the right thing, and it is why a naive text search of the HTML for "brewer's" finds nothing. It is also a small reminder that the string a reader sees, the string in the markup and the string in the address are three different encodings of one idea.
The aliases line shares the same discipline. It lists other wordings that map to the entry, drops any alias that is just the entry's own name, and sorts the rest, so a page never says "also called brewer's yeast" under a heading that already says it.
Takeaways
- Treat a published URL as an API. Names can be corrected, slugs cannot.
- Derive by default and override by exception, with a table that only holds the exceptions.
- Write the test for the thing a well meaning refactor would break, and put the reason in a comment where the assertion is.
- Check the rendered page, not only the data. The bug here was visible in a heading, not in any type.
