Skip to content

Commit 048b4e9

Browse files
committed
feat(a11y): add aria label on section headings anchor links
1 parent 1c3b53b commit 048b4e9

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

site/src/libs/astro.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import mdx from '@astrojs/mdx'
55
import sitemap from '@astrojs/sitemap'
66
import type { AstroIntegration } from 'astro'
77
import autoImport from 'astro-auto-import'
8-
import type { Element } from 'hast'
8+
import type { Element, Text } from 'hast'
99
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
1010
import { getConfig } from './config'
1111
import { rehypeBsTable } from './rehype'
@@ -59,7 +59,10 @@ export function bootstrap(): AstroIntegration[] {
5959
{
6060
behavior: 'append',
6161
content: [{ type: 'text', value: ' ' }],
62-
properties: { class: 'anchor-link' },
62+
properties: (element: Element) => ({
63+
class: 'anchor-link',
64+
ariaLabel: `Link to this section: ${(element.children[0] as Text).value}`
65+
}),
6366
test: (element: Element) => element.tagName.match(headingsRangeRegex)
6467
}
6568
],

0 commit comments

Comments
 (0)