Commit a429fa3
committed
fix(docs): slug correctness, anchor fallback, search UX overhaul
Audit on 17 pages of nodyx.dev surfaced 108 broken TOC links and 60
ugly leading-dash heading ids. Root causes were three independent bugs
in the slug + heading pipeline.
** Slug pipeline (src/lib/docs.server.ts) **
1. HTML entity mismatch. marked v12 passes the rendered HTML to
`renderer.heading`, where apostrophes have already been encoded to
`'`. The slugifier was stripping `&` and `;` (non-word) but
keeping `39`, producing ids like `the-real-fight-isn39t-between-us`.
Meanwhile `extractHeadings` ran on the raw markdown where the same
apostrophe is just `'` (stripped cleanly), yielding
`the-real-fight-isnt-between-us`. TOC href and heading id never
matched. Both call sites now go through `decodeHtmlEntities` first.
2. Leading + trailing dash from emoji-prefixed headings. `## 🎯 Pick
your mode` lowercased to ` pick your mode` (emoji stripped to
nothing, leaving a leading space) which became `-pick-your-mode`
after space-to-dash. Now trim leading/trailing dashes after
spacification and collapse internal runs (so em-dash + space + `--`
doesn't yield `a---b`).
3. Phantom TOC entries from code-block comments. The heading regex
matched `# 1. Stop pm2` inside ```bash fences as if it were an H1.
On INSTALL.md alone this leaked 11 fake "Clean Uninstall" steps
into the right sidebar, every one a dead link. New `stripFencedCode`
helper blanks fenced lines (preserving line count for offset math)
before extraction.
** Search modal (src/lib/components/Header.svelte) **
Reported by @lukasMega in #12: clicking the header search-trigger
required a second click on the input because focus didn't transfer.
Cmd+K worked. Root cause: HTML `autofocus` is unreliable for elements
mounted to the DOM after a user click (browser focus-trap mitigation).
Replaced with `bind:this` + `$effect` that calls `.focus()` on every
open. While in here:
- Keyboard nav: ↑/↓ moves selection, Enter opens, Esc closes,
selected row scrolls into view as the user arrows past the
visible area
- Matched terms wrapped in <mark> in result excerpts (longest-first
so phrase wraps don't double-mark individual words)
- Race-safe fetch: ignore stale responses if the user kept typing
while the previous request was in flight
- Hint footer (↑↓ navigate · ↵ open · esc close)
** Client-side anchor fallback (src/routes/[...slug]/+page.svelte) **
Old hand-written `[Foo](#-foo)` markdown links from when emoji slugs
had a leading dash now point at non-existent ids. Rather than rewriting
12 pages of source markdown, `applyLooseAnchor` resolves stale hashes
on mount and on every hashchange:
1. exact match (browser already handled it)
2. strip leading/trailing dashes + collapse internal runs
3. substring containment in either direction
4. token-based fallback (every dash-separated token must appear in
the heading text)
When a fallback resolves, `history.replaceState` rewrites the URL to
the canonical id so refresh + share-link both work.
** Audit numbers **
Heading ids: 362 (unchanged)
Leading-dash ids: 60 → 0
TOC links broken: 108 → 0
In-content broken: 10 → 34 (legacy `#-foo` links, now handled by
client-side fallback so users still
land on the right section)
Closes the focus bug from #12 second-pass feedback.1 parent 8722878 commit a429fa3
3 files changed
Lines changed: 339 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
| |||
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
26 | | - | |
27 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
28 | 111 | | |
29 | | - | |
| 112 | + | |
30 | 113 | | |
31 | | - | |
| 114 | + | |
32 | 115 | | |
33 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
34 | 159 | | |
35 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
36 | 163 | | |
37 | 164 | | |
38 | 165 | | |
| |||
103 | 230 | | |
104 | 231 | | |
105 | 232 | | |
106 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
107 | 236 | | |
108 | | - | |
109 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
110 | 241 | | |
111 | 242 | | |
112 | 243 | | |
113 | 244 | | |
114 | 245 | | |
| 246 | + | |
115 | 247 | | |
116 | 248 | | |
117 | 249 | | |
118 | 250 | | |
119 | 251 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
128 | 255 | | |
129 | 256 | | |
130 | 257 | | |
131 | 258 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
136 | 272 | | |
137 | 273 | | |
138 | 274 | | |
139 | 275 | | |
140 | 276 | | |
141 | 277 | | |
142 | 278 | | |
143 | | - | |
| 279 | + | |
144 | 280 | | |
145 | 281 | | |
146 | 282 | | |
147 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
148 | 289 | | |
149 | 290 | | |
150 | 291 | | |
| |||
287 | 428 | | |
288 | 429 | | |
289 | 430 | | |
| 431 | + | |
| 432 | + | |
290 | 433 | | |
291 | 434 | | |
292 | 435 | | |
| |||
317 | 460 | | |
318 | 461 | | |
319 | 462 | | |
320 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
321 | 471 | | |
322 | 472 | | |
323 | 473 | | |
| |||
327 | 477 | | |
328 | 478 | | |
329 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
330 | 487 | | |
331 | 488 | | |
332 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
333 | 493 | | |
334 | 494 | | |
335 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
336 | 509 | | |
337 | 510 | | |
338 | 511 | | |
339 | 512 | | |
340 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
341 | 529 | | |
0 commit comments