From 3663e3a061811798ca1ae8c0e2d2a73c85ecf1ad Mon Sep 17 00:00:00 2001 From: Maxime Lardenois Date: Sun, 25 May 2025 14:56:22 +0200 Subject: [PATCH] Docs: add aria label on section headings anchor links (#41487) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Co-authored-by: Julien Déramond Co-authored-by: Patrick H. Lauke --- site/src/libs/astro.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/site/src/libs/astro.ts b/site/src/libs/astro.ts index 3eb6947d34..01b4f6b106 100644 --- a/site/src/libs/astro.ts +++ b/site/src/libs/astro.ts @@ -5,7 +5,7 @@ import mdx from '@astrojs/mdx' import sitemap from '@astrojs/sitemap' import type { AstroIntegration } from 'astro' import autoImport from 'astro-auto-import' -import type { Element } from 'hast' +import type { Element, Text } from 'hast' import rehypeAutolinkHeadings from 'rehype-autolink-headings' import { getConfig } from './config' import { rehypeBsTable } from './rehype' @@ -59,7 +59,10 @@ export function bootstrap(): AstroIntegration[] { { behavior: 'append', content: [{ type: 'text', value: ' ' }], - properties: { class: 'anchor-link' }, + properties: (element: Element) => ({ + class: 'anchor-link', + ariaLabel: `Link to this section: ${(element.children[0] as Text).value}` + }), test: (element: Element) => element.tagName.match(headingsRangeRegex) } ], -- 2.47.2