Auto-indexing service and GraphQL API for AT Protocol Records

fix(www): preserve anchors when transforming .md links

Links like ./authentication.md#using-the-client-sdk now correctly
transform to /guides/authentication#using-the-client-sdk on the
rendered site while still working on GitHub.

+8 -5
+8 -5
www/src/www/page.gleam
··· 93 93 94 94 /// Transform .md links to clean paths 95 95 fn transform_links(html: String) -> String { 96 - // Match href="./something.md" or href="something.md" and replace with href="/something" 97 - let assert Ok(re) = regexp.from_string("href=\"(?:\\./)?([^\"]+)\\.md\"") 96 + // Match href="./something.md" or href="something.md" with optional anchor, replace with clean path 97 + let assert Ok(re) = 98 + regexp.from_string("href=\"(?:\\./)?([^\"#]+)\\.md(#[^\"]*)?\"") 98 99 regexp.match_map(re, html, fn(m) { 99 100 case m.submatches { 100 - [Some(filename)] -> 101 + [Some(filename), anchor] -> { 102 + let anchor_str = option.unwrap(anchor, "") 101 103 case filename { 102 - "README" -> "href=\"/\"" 103 - _ -> "href=\"/" <> filename <> "\"" 104 + "README" -> "href=\"/" <> anchor_str <> "\"" 105 + _ -> "href=\"/" <> filename <> anchor_str <> "\"" 104 106 } 107 + } 105 108 _ -> m.content 106 109 } 107 110 })