Repository navigation
Fix empty metadata and subtitle links in default listings - #15130
Merged
Merged
Conversation
The default listing template always wrapped the metadata block in a link to the post. When the block shows nothing (no date or author, fields that exclude every metadata field, or a listed custom field that is missing or empty on the post), the link is empty: a Tab stop with no accessible name, flagged by axe `link-name`. The link is now written only when the block has visible text. The guard follows the same field checks as the children it wraps, plus truthiness for extra fields, whose empty values render a bare ` `. The `.metadata` div stays on every item. In the row layout it is a flex item, so removing it on items without metadata would widen `.body` on those items only and make body widths differ within one listing.
The guard tested truthiness, but a custom field holding an empty list or a whitespace-only string is truthy and still renders no visible text, so the metadata link stayed empty for those posts. The same holds for `author`, which listing items carry as a list. The guard now asks whether each value renders as visible text: falsy values fall back to a bare ` `, and empty lists and blank strings stringify to whitespace. The children are unchanged.
The subtitle line was written whenever `subtitle` is in the listing fields, which it is by default, so every post without a subtitle got an empty link in its body: a Tab stop with no accessible name, flagged by axe `link-name`. It now uses the same visible-text check as the metadata link. Unlike the metadata column, the subtitle line has no layout role, so it is dropped entirely. Fixes #14380
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
Found while reviewing #15099 (empty thumbnail link, #15066): the default listing template has two more anchors that can end up empty, a Tab stop with no accessible name flagged by axe-core
link-name.dateandauthor; it is every post whenfieldsexcludes all of them, and any post where a listed custom field is missing or empty (a11y: default listing emits empty metadata <a> when a post has no date or author (link-name) #15129).subtitleis in the fields, which it is by default, so every post without a subtitle gets an empty link (a11y: default listing emits empty <a> when a post has no subtitle (link-name) #14380).Both have been there since the default listing template was introduced, so this is not a regression and there is no backport.
Fix
The template now checks whether a value renders as visible text (
hasText()). Falsy values render as throughoutputLink(), and empty lists and blank strings stringify to whitespace, so none of them count. The metadata link is written only when one of its fields has text, and the subtitle line only when the subtitle has text.The
.metadatadiv itself is kept on every post. It is a flex column in the row layout, so dropping it on some posts would widen.bodyon those posts only and make widths differ within one listing. The subtitle line has no such role and is dropped entirely.A custom field whose value is HTML rendering nothing (e.g.
" ") still gives an unnamed link. Catching it would need HTML parsing in the EJS template for author-provided content, which was deemed out of scope.The new smoke test covers the default fields, fields without any metadata, reading time only, and a custom field that is present, missing, empty, blank or an empty list. axe-core in Chromium on the same listing pages reports no
link-nameviolation.Fixes #15129, fixes #14380
Checklist
I have (if applicable):
tests/smoke/site/, not the full suite)AI-assisted PR
Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.