From 809fed4308b1e2a9bbbd8623a7ecf9ea6dd6116c Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Thu, 19 May 2022 13:21:10 -0700 Subject: [PATCH] Accessible in-page heading anchors! Bit the bullet and decided to make anchors that look great to terminal/textual browsers, ARIA + screen reader combos, and a regular browser. --- assets/css/dark.css | 11 ++++-- assets/css/main.css | 17 +++++++-- layouts/_default/_markup/render-heading.html | 38 ++++++-------------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/assets/css/dark.css b/assets/css/dark.css index 52be18f..f90cebd 100644 --- a/assets/css/dark.css +++ b/assets/css/dark.css @@ -16,7 +16,7 @@ /* Small text needs higher contrast */ sup { - background-color: #0b0b0b; + background-color: #000; } /* Only color if it's a link; if href is empty, let it be. */ @@ -24,12 +24,17 @@ color: #f1e7b2; } + a:active { + color: #b93; + } + a:visited { color: #fdf; } - a:active { - color: #b93; + /* Small text needs higher contrast */ + sup a:visited { + color: #ffe3ff; } /* stylelint-disable -- hasn't heard of "prefers-contrast" yet */ diff --git a/assets/css/main.css b/assets/css/main.css index 52731e3..a879ac3 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -77,11 +77,16 @@ html { /* Compensate for misalignment and wasted space caused by padding * and margin adjustments in nav children made to meet SC 2.5.5 */ + header > nav, + footer > nav, + h2 + a { + margin-left: -.25em; + } header > nav { - margin: 0 0 -.75em -.25em; + margin-bottom: -.75em; } footer > nav { - margin: -.75em 0 0 -.25em; + margin-top: -.75em; } summary { @@ -107,8 +112,14 @@ html { padding: 1em 0; } - /* SC 2.5.5, Google a11y: Increase tap target size a bit */ + /* SC 2.5.5, Google a11y: Increase tap target size a bit + * - Summary is a tappable button + * - standalone links in lists are usually parts of collections of + * links that should be easy to fat-finger + * - links that directly follow h2 without being contained in a + * paragraph are section permalinks. */ summary, + h2 + a, li > a { padding: .875em .25em; } diff --git a/layouts/_default/_markup/render-heading.html b/layouts/_default/_markup/render-heading.html index e57b7ea..8919bb9 100644 --- a/layouts/_default/_markup/render-heading.html +++ b/layouts/_default/_markup/render-heading.html @@ -1,29 +1,11 @@ -{{- with . -}} -{{ .Text | safeHTML -}} -{{- if and (gt .Level 1) (eq .Page.Section "posts") -}} - - {{- $octothorpes := sub .Level 1 -}} - {{- range $i, $sequence := (seq $octothorpes) -}} - {{- print `#` -}} - {{- end -}} - +{{- if and (eq .Level 2) (eq .Page.Section "posts") }} +{{ .Text | safeHTML -}} + + Permalink to section + +{{- else }} +{{- with . -}} +{{ .Text | safeHTML -}}{{ end -}} {{- end }} -{{ end }}