* Append a `[X.Y.Z]: https://github.com/colbymchenry/codegraph/releases/tag/vX.Y.Z` * link reference at the end of the file IF one doesn't already exist. The * link ref is what makes `## [X.Y.Z]` heading text auto-link to its tag in * GitHub's renderer; without it the heading still renders, just
(text, version)
| 251 | * which CommonMark accepts regardless. |
| 252 | */ |
| 253 | function appendLinkRef(text, version) { |
| 254 | const refLine = `[${version}]: https://github.com/colbymchenry/codegraph/releases/tag/v${version}`; |
| 255 | // Already there? Look for a line that EQUALS this (anywhere in the file) |
| 256 | // to keep idempotency robust against the scattered-vs-block layout. |
| 257 | const lines = text.split('\n'); |
| 258 | if (lines.some((l) => l.trim() === refLine)) return text; |
| 259 | // Append, separated by a blank line from the prior content. Preserve a |
| 260 | // single trailing newline at EOF. |
| 261 | const trailingNewline = text.endsWith('\n') ? '' : '\n'; |
| 262 | return text + trailingNewline + refLine + '\n'; |
| 263 | } |
| 264 | |
| 265 | try { |
| 266 | main(); |