Skip to content

Commit 4256ada

Browse files
committed
nav: home emoji (text-variation), "Parts:" label, SW skip on localhost
Three related changes after testing the TOC flow locally. 1. Home pill: plain-text "TOC" / "Index" / "All parts" all read as visual noise. Swap to 🏠 with a trailing U+FE0E text-variation selector so browsers render the outlined monochrome house glyph instead of the full-color emoji. Tooltip + aria-label carry the semantic name ("Back to the walkthrough index") for keyboard + SR users. Drop the `::before { content: '«' }` — the emoji itself is the affordance. 2. Part pill labels: meander emits eight "Part N" pills, which reads as repetitive "Part 1 Part 2 Part 3…". walkthrough-drag.js now rewrites pill text to just "1", "2", …, "8" and prepends a shared "Parts:" label. The label is a <span>, styled as a muted uppercase column header, not a pill. Same-order read: 🏠 | Parts: | 1 2 3 4 5 6 7 8. 3. SW on localhost: installing the SW locally made rapid iteration painful — the first load cached HTML/CSS, then every subsequent edit served stale bytes until DevTools → Unregister + Clear site data. Skip SW registration on localhost / 127.0.0.1 and proactively unregister any prior SW so the next fetch goes to the network. Production (GH Pages) registers normally — cache-first pays off for real users.
1 parent dba3a27 commit 4256ada

3 files changed

Lines changed: 63 additions & 12 deletions

File tree

scripts/walkthrough.mts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,22 @@ async function generate(
495495
// work. `updateViaCache:'none'` forces the browser to fetch the SW
496496
// file itself via HTTP cache (not its own SW cache), so a new
497497
// deploy's SW is picked up on the next reload.
498+
// Skip SW registration on localhost / 127.0.0.1 so rapid iteration
499+
// doesn't get stuck on stale cached HTML/assets served by a prior
500+
// SW install. If an SW is already registered from a previous load,
501+
// unregister it so the very next fetch goes to the network. Prod
502+
// (GH Pages) registers normally — cache-first pays off there.
498503
const swRegisterTag = [
499504
'<script>',
500505
" if ('serviceWorker' in navigator) {",
501-
" addEventListener('load', () => {",
502-
" navigator.serviceWorker.register('/walkthrough-sw.js', { updateViaCache: 'none' }).catch(() => {})",
503-
' })',
506+
' var isLocal = /^(localhost|127\\.0\\.0\\.1)$/.test(location.hostname)',
507+
' if (isLocal) {',
508+
' navigator.serviceWorker.getRegistrations().then(rs => rs.forEach(r => r.unregister())).catch(() => {})',
509+
' } else {',
510+
" addEventListener('load', () => {",
511+
" navigator.serviceWorker.register('/walkthrough-sw.js', { updateViaCache: 'none' }).catch(() => {})",
512+
' })',
513+
' }',
504514
' }',
505515
'</script>',
506516
].join('\n ')
@@ -592,7 +602,7 @@ async function generate(
592602
) {
593603
html = html.replace(
594604
'<div class="part-nav">',
595-
'<div class="part-nav"><a class="wt-home-link" href="/" aria-label="Back to the walkthrough table of contents">TOC</a>',
605+
'<div class="part-nav"><a class="wt-home-link" href="/" aria-label="Back to the walkthrough index" title="Back to index">🏠︎</a>',
596606
)
597607
}
598608

walkthrough-drag.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,39 @@
388388
}, 1500)
389389
})
390390

391+
// Compact the meander-emitted Part pill labels from "Part 1", "Part 2",
392+
// … down to just the number, and prepend a shared "Parts:" label.
393+
// Eight "Part N" pills read as repetitive noise; one label + eight
394+
// numerals communicate the same grouping with less visual weight.
395+
// The home (🏠) pill we inject in the post-processor keeps its emoji
396+
// — it's not a numbered part, so the `Part ` prefix isn't there
397+
// to strip.
398+
const installPartNavLabels = () => {
399+
const nav = document.querySelector('.topbar .part-nav')
400+
if (!nav || nav.querySelector('.wt-parts-label')) {
401+
return
402+
}
403+
const pills = nav.querySelectorAll('a:not(.wt-home-link)')
404+
for (const a of pills) {
405+
const m = a.textContent?.match(/^Part\s+(\d+)/)
406+
if (m) {
407+
a.textContent = m[1]
408+
}
409+
}
410+
if (pills.length > 0) {
411+
const label = document.createElement('span')
412+
label.className = 'wt-parts-label'
413+
label.textContent = 'Parts:'
414+
// Insert label right before the first numbered pill — after the
415+
// home link if present, otherwise at the nav's start.
416+
pills[0].before(label)
417+
}
418+
}
419+
391420
const ready = async () => {
392421
installAll()
393422
installThemeToggle()
423+
installPartNavLabels()
394424
await waitForHljs()
395425
// Fallback reveal for pages with no comment shim (documents, or
396426
// walkthroughs with no commentBackend). When the shim IS present,

walkthrough-overrides.css

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -695,18 +695,29 @@ body.wt-ready .topbar-actions {
695695
.ok {
696696
color: var(--muted-lavender) !important;
697697
}
698-
/* "All parts" home link on every part page. Leading chevron makes it
699-
* unambiguous it's a back-nav, not another Part pill. Slight right
700-
* margin + brighter border separate it from the numbered pills so it
701-
* reads as a distinct category ("root" vs "children"). */
698+
/* Emoji-only home link on every part page — 🏠 reads as "go back
699+
* to the index" without needing a word label. Slight right margin +
700+
* brighter border separate it from the numbered Part pills so it
701+
* reads as a distinct category ("root" vs "children"). Tooltip
702+
* (title attribute on the anchor) carries the label for keyboard /
703+
* screen-reader users; visual users read the glyph. */
702704
.topbar .part-nav a.wt-home-link {
703705
border-color: rgba(255, 255, 255, 0.55) !important;
704706
margin-right: 8px;
705707
}
706-
.topbar .part-nav a.wt-home-link::before {
707-
content: '« ';
708-
margin-right: 2px;
709-
opacity: 0.8;
708+
/* "Parts:" label prepended by walkthrough-drag.js once the topbar has
709+
* mounted. Eight numbered pills read as repetitive "Part 1 Part 2 Part
710+
* 3…"; this turns it into "Parts: 1 2 3 4 5 6 7 8". The label itself
711+
* is a <span>, not a pill — same translucent-white as the pill text
712+
* so it reads as the column header. */
713+
.topbar .part-nav .wt-parts-label {
714+
color: rgba(255, 255, 255, 0.72);
715+
margin-right: 4px;
716+
align-self: center;
717+
font-size: 12px;
718+
text-transform: uppercase;
719+
letter-spacing: 0.06em;
720+
font-weight: 600;
710721
}
711722
/* Dark theme keeps the same purple band — docs.socket.dev uses the
712723
* same header in both modes, deepened slightly against the near-black

0 commit comments

Comments
 (0)