Fix category chips: dead links, and the wrong category on the card - #205
Merged
Conversation
The category chip on an article card is a link, and its target was derived
from the category NAME alone. That silently produced URLs no page answers:
"Men's Basketball" canonicalizes to "men-s-basketball" while the
subsection lives at "mens-basketball", so the chip 404s.
/mens-basketball 200 the real page
/men-s-basketball 404 what the chip linked to
Both basketballs and both soccers -- the four apostrophe subsections --
have been like this the whole time. It is the same apostrophe
possessiveVariant already absorbs on the matching side; the link never got
the same treatment. Nobody reported it because a chip is a small target
and the article underneath it works.
Resolve through site_taxonomy instead, falling back to the derived slug so
the value is never empty. A category that only reaches a section by alias
now links to that section rather than to nothing, which is what makes the
chip on a men's lacrosse article useful.
RefreshCategoryAliases now loads every section and subsection rather than
only the rows carrying aliases, because a row with no alias still has to
resolve -- that is most of them.
A row's own title outranks any alias: an alias is how a section absorbs
somebody else's category, so it must never take the link away from that
category's own page. The chip should reach the most specific page that
lists the article. Covered by an integration test, run against MariaDB
11.7 rather than left to skip.
Tags are deliberately untouched: they have no taxonomy rows and their
derived slugs are all they have.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An editor reported the Columns block labelling a column "MEN'S LACROSSE". The card shows one category as its kicker and takes the first one; that article is ["Men's Lacrosse", "From the Playbook", "Sports"], it is in Columns because of From the Playbook, and it announced itself as a sport. Order the categories where the section is already known, rather than teaching the card to guess. The handler is the only place that knows which section was asked for, and doing it there fixes every surface at once -- homepage blocks, section pages, subsection pages, filtered listings -- without changing a single component. This is why the chip slugs had to be resolved through the taxonomy first: matching a category against the section's slugs only works if the category carries the slug the section knows it by. "Men's Lacrosse" reaches Sports by alias, so on a Sports page it leads; in Columns, From the Playbook does. A subsection stands on its own. On a subsection page the subsection is the reason the article is there, not the parent section it also carries. Listings with no section -- an author page, an unfiltered feed -- pass nothing and keep the article's own order, because no category is more relevant than another there. Single articles are untouched for the same reason. The sort is a stable partition, so two categories that are both in the section keep the article's order between them and the kicker does not move for unrelated reasons. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Two defects behind Janine's screenshot of a men's lacrosse article showing under Columns. The second is what she reported; the first I found alongside it and is live right now.
1. Chips link to pages that don't exist
The chip is a link, and its target was derived from the category name alone via
CanonicalizeSlug, independent ofsite_taxonomy:Both basketballs and both soccers — the four apostrophe subsections — have had dead chips this whole time. Same apostrophe
possessiveVariantalready absorbs on the matching side; the link never got the same treatment. Nobody reported it because a chip is a small target and the article underneath works.Now resolved through
site_taxonomy, falling back to the derived slug so the value is never empty. A category that only reaches a section by alias — men's lacrosse after #199 — links to that section instead of nowhere.Two things to review:
RefreshCategoryAliasesloads every section and subsection now, not just rows with aliases, because a row with no alias still has to resolve. That's most of them."Men's Basketball"alias onsportswould have sent the basketball chip to/sportsinstead of its own page. A chip should reach the most specific page listing the article.Tags are deliberately untouched: no taxonomy rows, so derived slugs are all they have.
2. The card shows the wrong category
The card takes
categories[0]. That article is["Men's Lacrosse", "From the Playbook", "Sports"]— it's in Columns because of From the Playbook, but it announced itself as a sport.Ordered in the handler rather than taught to the card: the handler is the only place that knows which section was asked for, so doing it there fixes every surface at once — homepage blocks, section pages, subsection pages, filtered listings — with no component changes.
The two fixes are coupled, which is why they're one PR: matching a category against the section's slugs only works once the category carries the slug the section knows it by. Fix 1 is what makes fix 2 possible.
Rules:
Testing
go build,go vet, full suite green. The database integration tests were run against a real MariaDB 11.7 rather than left to skip on a missingCMS_TEST_DSN, including the new alias-vs-own-page precedence case.One thing the unit tests can't cover: a possessive category only resolves to its slug through the taxonomy cache, which lives in the database package and can't be loaded from a handlers test. The ordering tests use Field Hockey instead, and the comment says why.
🤖 Generated with Claude Code