Commit fc95bf5
feat: relative links, TOC generation, and link validation (#1)
* feat: transform relative links to absolute paths
Fix <base href="/"> issue where #anchor links navigate to /#anchor.
The build now transforms relative links to absolute paths:
- #section → /blog/slug#section
- ../other-slug → /blog/other-slug
- ../other-slug#section → /blog/other-slug#section
Uses path.posix.resolve() for cross-platform path resolution.
linkBasePath is derived from folder structure (folder = URL path).
Also fixes: mailto:, tel:, ftp:// links are now correctly preserved
(isAbsoluteUrl uses /^\w+:/ regex to match all protocols).
Includes comprehensive documentation of URL transformation system.
* feat: add automatic TOC generation with [[toc]] marker
- Add TOC_MARKER constant for [[toc]] placeholder
- Add generateToc() using getHeadingList() from marked-gfm-heading-id
- Add decodeHtmlEntities() for proper heading text display
- Include h2 and h3 headings, skip headings before marker
- Generate nested markdown list that gets processed normally
Also includes:
- Tests for mailto:, tel:, ftp:// links (not transformed)
- Tests for TOC generation (6 new tests)
* fix: add missing type exports and update test parameters
- Add HeadingData, getHeadingList, and resetHeadings exports to types.d.ts
- Add missing linkBasePath parameter to markdownToEntry test calls
* docs: comprehensive README with feature documentation
- Document image URL transformation (placeholder system)
- Document link transformation (relative to absolute)
- Document TOC generation with [[toc]] marker
- Add YAML frontmatter reference
- Add architecture overview
- Add submodule warning
* docs: clarify Angular website reference
* docs: translate README to English
* refactor: replace marked-gfm-heading-id with inline fork
- Fork marked-gfm-heading-id to shared/gfm-heading-id/
- Convert to TypeScript with improved types
- Simplified API (removed unused globalSlugs option)
- Better entity handling (decode before slugging)
- Replace marked-gfm-heading-id dependency with github-slugger
- Remove now-empty types.d.ts
- Update README with github-slugger reference
The fork is only 100 lines and gives us full control over heading ID
generation. All 131 tests pass.
* refactor: simplify TOC generation using h.raw from fork
- Remove decodeHtmlEntities() from JekyllMarkdownParser (now in fork)
- Use h.raw directly instead of decoding h.text
- Update comment to reference our gfm-heading-id fork
The fork provides heading.raw which is already decoded and stripped
of HTML tags, eliminating duplicate code.
* refactor: major cleanup and simplification
Code Quality Improvements:
- Extract shared utilities to html.utils.ts (stripHtmlTags, decodeHtmlEntities, escapeHtml)
- Precompile regex patterns for better performance
- Simplify parse() return type (remove unused yaml/markdown fields)
- Update documentation to reference our gfm-heading-id fork
TOC Generation Simplification:
- Replace complex position-tracking algorithm with simple split approach
- Split markdown at [[toc]] marker, parse only content after it
- Reduces generateToc from 60+ lines to 30 lines
- More robust: no regex matching of heading text needed
Net result: -40 lines of code, cleaner architecture, same functionality.
All 131 tests pass.
* feat: preserve HTML formatting in TOC links + add comprehensive tests
- TOC links now preserve inline formatting (<code>, <strong>, <em>)
- Add warning for duplicate headings (known limitation)
- Move gfm-heading-id.ts out of subdirectory
- Add html.utils.spec.ts (45 tests)
- Add gfm-heading-id.spec.ts (24 tests)
- Add 5 TOC formatting tests
- Document HeadingData text vs raw separation
- Clarify slug terminology in base.types.ts
Total: 205 tests passing
* feat: add anchor link validation with fuzzy "did you mean?" suggestions
Build-time validation for broken anchor links:
- Collects all heading IDs during parsing
- Extracts all anchor links from HTML
- Validates links point to existing anchors
- Suggests similar anchors using Levenshtein distance (typo detection)
- Warnings only, does not fail the build
New files:
- string.utils.ts: Levenshtein distance + findSimilar (27 tests)
- link-validator.ts: Anchor validation logic (14 tests)
Changes:
- jekyll-markdown-parser.ts: Now returns headingIds
- base.utils.ts: Registers anchors and links during parsing
- build.ts: Runs validation at end of build
Total: 246 tests passing
* fix(README): indentation
* refactor: improve code quality based on audit findings
- link-validator: use matchAll() instead of exec() loop with global regex
- html.utils: add single quote escaping for complete HTML safety
- base.utils: replace string concat sort key with proper multi-field comparison
* fix: skip external URLs in anchor link validation
* fix: URL-decode anchors before validation
* feat: include h4 headings in [[toc]] generation
---------
Co-authored-by: Ferdinand Malcher <ferdinand@malcher.media>1 parent 7b9f23b commit fc95bf5
19 files changed
Lines changed: 2387 additions & 154 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 19 | + | |
27 | 20 | | |
28 | 21 | | |
29 | | - | |
| 22 | + | |
| 23 | + | |
30 | 24 | | |
31 | | - | |
32 | | - | |
| 25 | + | |
| 26 | + | |
33 | 27 | | |
34 | | - | |
| 28 | + | |
35 | 29 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 30 | + | |
| 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 | + | |
40 | 86 | | |
41 | 87 | | |
42 | | - | |
| 88 | + | |
43 | 89 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
47 | 125 | | |
48 | | - | |
| 126 | + | |
49 | 127 | | |
50 | | - | |
| 128 | + | |
51 | 129 | | |
52 | | - | |
| 130 | + | |
53 | 131 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 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 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | | - | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
0 commit comments