Skip to content

Commit 34e8108

Browse files
authored
Fix empty metadata and subtitle links in default listings (#15130)
The default listing template wrapped the metadata block and the subtitle line in links to the post even when neither showed any visible text. Those links had no accessible name, which axe-core flags as a link-name violation and which made an empty Tab stop for keyboard users. Each link is now written only when its content renders visible text. - Write the metadata link only when one of its fields has visible text. The .metadata div stays on every item so body widths match within a listing. - Write the subtitle line only when the post has a subtitle. - Treat falsy values, empty lists and blank strings as no visible text. The empty thumbnail link had the same problem and was fixed separately in #15099. Fixes #14380 Fixes #15129
1 parent d0bc2d9 commit 34e8108

14 files changed

Lines changed: 193 additions & 4 deletions

File tree

‎news/changelog-1.11.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ All changes included in 1.11:
2828
- ([#14376](https://github.com/quarto-dev/quarto-cli/issues/14376)): Translate the new `navigation-*-label` keys in all 33 built-in language files. The values are drawn from existing human-translated interface strings (LibreOffice, GNOME, Wikidata) and each one carries a comment naming its source; values that were adapted rather than used verbatim are marked `needs review`.
2929
- ([#14376](https://github.com/quarto-dev/quarto-cli/issues/14376)): Label the table of contents `<nav>` with its localized title (`aria-labelledby`), in `html` and `revealjs` output, so assistive technology can tell it apart from other navigation landmarks.
3030
- ([#14378](https://github.com/quarto-dev/quarto-cli/issues/14378)): Make scrollable code blocks and cell output keyboard-focusable in HTML output, so keyboard users can Tab to them and scroll with the arrow keys (axe rule `scrollable-region-focusable`, WCAG 2.1.1). While a region overflows it gets `tabindex="0"`, `role="group"`, and a localized `aria-label` (new `scrollable-code-label` and `scrollable-output-label` language keys, translated in all 34 built-in language files); when it fits again the attributes are removed. Chrome and Firefox already focus such regions natively; this adds Safari coverage and an accessible name.
31+
- ([#14380](https://github.com/quarto-dev/quarto-cli/issues/14380)): Fix default listings rendering an empty, focusable subtitle link for posts without a subtitle, flagged by axe-core (`link-name`).
3132
- ([#14795](https://github.com/quarto-dev/quarto-cli/issues/14795)): Fix keyboard focus in `revealjs` presentations reaching links and controls on nearby slides that are not shown. Tab now stays on the current slide, except in overview, scroll and print views where all slides are shown.
3233
- ([#14952](https://github.com/quarto-dev/quarto-cli/issues/14952)): Fix `revealjs` presentations disabling pinch-zoom on touch devices. The viewport `<meta>` tag no longer sets `maximum-scale=1.0` and `user-scalable=no`, which axe-core flagged (`meta-viewport`).
3334
- ([#14968](https://github.com/quarto-dev/quarto-cli/issues/14968)): The header of notebook preview pages (back link, notebook title, download link) is now a navigation landmark named after the notebook, so it is reachable through landmark navigation and no longer flagged by axe-core (`region`).
@@ -39,6 +40,7 @@ All changes included in 1.11:
3940
- ([#15066](https://github.com/quarto-dev/quarto-cli/issues/15066)): Fix default listings rendering an empty, focusable thumbnail link for posts without a preview image, flagged by axe-core (`link-name`); the link is now hidden from assistive technology and taken out of the tab order. (author: @chanellebingham)
4041
- ([#15079](https://github.com/quarto-dev/quarto-cli/issues/15079)): Fix keyboard focus in `revealjs` presentations moving to the page when coming back to the presentation's browser tab, which took readers off the link or chart they were on and made screen readers stop passing the arrow keys to the presentation. (author: @jooyoungseo)
4142
- ([#15080](https://github.com/quarto-dev/quarto-cli/issues/15080)): Fix footnote, citation, cross-reference and code annotation popups not closing with Esc, and staying open over the next focused element after keyboard focus leaves them.
43+
- ([#15129](https://github.com/quarto-dev/quarto-cli/issues/15129)): Fix default listings rendering an empty, focusable metadata link for posts with no date, author or other listed field to show, flagged by axe-core (`link-name`).
4244

4345
## Formats
4446

‎src/resources/projects/website/listing/item-default.ejs.md‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ return !["title", "image", "image-alt", "date", "author", "subtitle", "descripti
1414
// Capture the item number for utility functions that need it
1515
const itemNumber = listing.utilities.itemNumber();
1616

17-
// Writes a metadata value
18-
const outputMetadata = (item, field) => {
19-
17+
// Reads a (possibly dotted) metadata field from an item
2018
const readField = (item, field) => {
2119
let value = item[field];
2220
if (field.includes(".") && !field.endsWith(".") && !field.startsWith(".")) {
@@ -29,6 +27,21 @@ value = value[deref];
2927
return value;
3028
}
3129

30+
// Whether a value renders as visible text (falsy values render as &nbsp;,
31+
// empty lists and blank strings as whitespace)
32+
const hasText = (value) => !!value && String(value).trim() !== "";
33+
34+
// Whether the metadata block shows any text for the item
35+
const hasMetadata = (item) => {
36+
return (fields.includes('date') && hasText(item.date)) ||
37+
(fields.includes('author') && hasText(item.author)) ||
38+
(fields.includes('reading-time') && hasText(item['reading-time'])) ||
39+
otherFields.some(field => hasText(readField(item, field)));
40+
}
41+
42+
// Writes a metadata value
43+
const outputMetadata = (item, field) => {
44+
3245
let value = readField(item, field);
3346
if (value !== undefined) {
3447
print(`<div class="metadata-value listing-${field}">${listing.utilities.outputLink(item, field, value)}</div>`);
@@ -56,7 +69,7 @@ print(`<div class="metadata-value listing-${field}">${listing.utilities.outputLi
5669

5770
<% if (fields.includes('title')) { %>
5871
<h3 class="no-anchor listing-title"><a href="<%- item.path %>" class="no-external"><%= item.title %></a></h3>
59-
<% if (fields.includes('subtitle')) { %>
72+
<% if (fields.includes('subtitle') && hasText(item.subtitle)) { %>
6073
<div class="listing-subtitle"><a href="<%- item.path %>" class="no-external"><%= item.subtitle %></a></div>
6174
<% } %>
6275
<% } %>
@@ -91,10 +104,14 @@ print(`<div class="metadata-value listing-${field}">${listing.utilities.outputLi
91104

92105
::: {.metadata}
93106

107+
<% if (hasMetadata(item)) { %>
108+
94109
```{=html}
95110
<a href="<%- item.path %>" class="no-external">
96111
```
97112

113+
<% } %>
114+
98115
<% if (fields.includes('date') && item.date) { %>
99116
<div class="listing-date"><%= item.date %></div>
100117
<% } %>
@@ -115,10 +132,14 @@ print(`<div class="metadata-value listing-${field}">${listing.utilities.outputLi
115132
<% outputMetadata(item, field) %>
116133
<% } %>
117134

135+
<% if (hasMetadata(item)) { %>
136+
118137
```{=html}
119138
</a>
120139
```
121140

141+
<% } %>
142+
122143
:::
123144

124145
:::
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.quarto/
2+
_site/
3+
4+
**/*.quarto_ipynb
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project:
2+
type: website
3+
4+
website:
5+
title: "Listing metadata link"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "Posts with a custom field"
3+
listing:
4+
contents: posts
5+
type: default
6+
sort: "title"
7+
fields: [title, version]
8+
---
9+
10+
A default listing with a custom metadata field.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "Posts without metadata fields"
3+
listing:
4+
contents: posts
5+
type: default
6+
sort: "title"
7+
fields: [image, title]
8+
---
9+
10+
A default listing whose fields exclude every metadata field.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "Posts"
3+
listing:
4+
contents: posts
5+
type: default
6+
sort: "title"
7+
---
8+
9+
A default listing with the default fields. The post without a date or
10+
an author has nothing to show in its metadata block.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "Post with a blank version"
3+
version: " "
4+
---
5+
6+
Text.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: "Post with a date and an author"
3+
date: 2026-01-01
4+
author: "Jane Doe"
5+
subtitle: "A subtitle"
6+
version: "1.0"
7+
---
8+
9+
Text.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: "Post with an empty version list"
3+
version: []
4+
---
5+
6+
Text.

0 commit comments

Comments
 (0)