@@ -77,12 +77,23 @@ function extractToc(html) {
7777 * sidecar `<basename>.toc.html` file so doc-page.js can render it in its
7878 * own sidebar slot.
7979 */
80+ /**
81+ * Rewrite legacy hash-router links (href="#/anchor/x", href="#/about", …)
82+ * that authors used in the .adoc sources to real clean URLs, so the
83+ * pre-rendered pages are navigable without JavaScript and crawlable (#599).
84+ * In-page TOC/section links (href="#section-id", no slash) stay untouched.
85+ * With JS the router intercepts the clean URLs for SPA navigation.
86+ */
87+ function rewriteLegacyHashLinks ( html ) {
88+ return html . replace ( / h r e f = " # \/ / g, 'href="/Semantic-Anchors/' )
89+ }
90+
8091function renderFile ( srcPath , destPath , quiet = false ) {
8192 if ( ! fs . existsSync ( srcPath ) ) return
8293 try {
8394 fs . mkdirSync ( path . dirname ( destPath ) , { recursive : true } )
8495 const html = String ( asciidoctor . convertFile ( srcPath , { ...OPTS , to_file : false } ) )
85- const { toc, body } = extractToc ( html )
96+ const { toc, body } = extractToc ( rewriteLegacyHashLinks ( html ) )
8697 fs . writeFileSync ( destPath , body , 'utf-8' )
8798 if ( ! quiet ) console . log ( `Rendered: ${ path . relative ( ROOT , destPath ) } ` )
8899 const tocPath = destPath . replace ( / \. h t m l $ / , '.toc.html' )
0 commit comments