Skip to content

Commit e1ab7f0

Browse files
committed
feat: highlighting accessivility violations
1 parent a50556e commit e1ab7f0

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@types/koa": "^3.0.1",
1010
"@types/koa-static": "^4.0.4",
1111
"@types/node": "^24.9.2",
12+
"axe-core": "^4.11.0",
1213
"axe-sarif-converter": "^3.0.0",
1314
"github-actions-ctrf": "^0.0.58",
1415
"koa": "^3.1.1",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/a11y-debug/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
params:
2+
accessibility:
3+
showViolations: true

src/layouts/partials/extend_footer.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,31 @@
44
{{- $custom := resources.Get "js/quick.search.js" | minify | fingerprint -}}
55
<script defer src="{{ $custom.Permalink }}" integrity="{{ $custom.Data.Integrity }}" crossorigin="anonymous"></script>
66
{{- end -}}
7+
{{- if site.Params.Accessibility.ShowViolations -}}
8+
<script src="https://cdn.jsdelivr.net/npm/axe-core/axe.min.js" integrity="sha256-6eWGPDOodPCbwBrNkjS348hxR59e74gC+lglREZebQE=" crossorigin="anonymous"></script>
9+
<script>
10+
axe
11+
.run()
12+
.then(results => {
13+
results.violations.forEach(v => {
14+
const message = `[${v.impact}] ${v.help}: ${v.description}\n(${v.id}: ${v.helpUrl})`;
15+
const colors = {
16+
critical: 'rgba(255, 0, 0, 1)',
17+
serious: 'rgba(255, 0, 0, .5)',
18+
moderate: 'rgba(255, 255, 0, 1)',
19+
minor: 'rgba(255, 255, 0, .5)'
20+
};
21+
v.nodes.forEach(n => {
22+
n.target.forEach(selector => {
23+
const el = document.querySelector(selector);
24+
if (el) {
25+
el.style.outline = `3px solid ${colors[v.impact] || colors.minor}`;
26+
el.style.outlineOffset = '2px';
27+
el.setAttribute('title', message);
28+
}
29+
})
30+
})
31+
})
32+
})
33+
</script>
34+
{{- end -}}

0 commit comments

Comments
 (0)