Skip to content

fix(website/listing): resolve category links to nearest parent listing - #14495

Merged
cderv merged 10 commits into
quarto-dev:mainfrom
mcanouil:fix/issue14493
Oct 19, 2026
Merged

cderv merged 10 commits into
quarto-dev:mainfrom
mcanouil:fix/issue14493

Conversation

@mcanouil

@mcanouil mcanouil commented May 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When a post appears in more than one listing, its category links could point at the wrong one.
In #14493, a post under blog/ that the home page also lists linked its categories to index.html#category=..., which does not filter anything.

findNearestParentListing never matched, because it compared a path without a leading slash against listing paths that have one.
So the choice fell to the referrer, or to the first entry in listings.json, whose order depends on how the site was rendered.
It now keeps the deepest listing whose directory holds the post.

The listing the reader came from still wins when the nearest one is no more specific: the site root listing, or another listing in the same directory.
The referrer is compared by pathname and origin, so this also works on a site served under a subpath.

The Playwright tests serve listings.json in two explicit orders, with the home page listing last and first, as the rendered order differs between machines.
Each one fails without its fix in Chromium, Firefox and WebKit.
An axe scan of the test site finds the same issues with and without this change.

Fixes #14493

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR
AI-assisted PR
  • AI tool used: Claude Code.
  • Codebase grounding: local clone.
  • Human review: I have reviewed, tested, and verified the AI-generated content before submitting.

Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.

@posit-snyk-bot

posit-snyk-bot commented May 6, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mcanouil mcanouil self-assigned this Jul 22, 2026
When a post is included in multiple listings (for example a homepage that
lists everything plus a blog listing under `blog/`), the category badges on
the post page wired to the wrong listing href. The previous prefix walk in
`findNearestParentListing` stripped the leading slash from the post path
before comparing against listing pathnames that retained theirs, so no
listing ever matched and the function returned `undefined`. The caller then
fell back to `document.referrer` or `listingHrefs[0]`, neither of which
tracks the post's actual position in the directory tree.

Replace the walk with a longest-directory-prefix match anchored at path
boundaries: each listing is reduced to its containing directory, and the
deepest directory that prefixes the post's directory wins. The fallback to
referrer and first listing is retained for posts that are not under any
listing's directory.

Closes quarto-dev#14493

@cderv cderv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good to me.

I'll push a small adjustment to the tests and resolve the changelog conflict with main before merging, so no need to push on your side.

cderv added 2 commits October 19, 2026 15:43
The order of listings.json depends on how the site was rendered. On a
Windows render, blog/archive.html came before blog/index.html, so the
same-directory test passed without the tie-break between listings.
Both cases now serve a fixed order with the blog listing before the
archive, so each test fails without its fix whatever the render order.

Also ignore *.quarto_ipynb in the fixture, which a render adds to its
.gitignore.
@cderv
cderv merged commit 7280ff1 into quarto-dev:main Oct 19, 2026
51 checks passed
@mcanouil
mcanouil deleted the fix/issue14493 branch October 19, 2026 14:36
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.

Wrong category link when post is contained in multiple listings

3 participants