Skip to content

Commit c07685f

Browse files
committed
fix: replace anchor-only urls with absolute ones
1 parent 6b23ea7 commit c07685f

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/Web/assets/fix-anchors.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// The server currently adds trailing slashes, which means all links using anchors will
2+
// lead to full-page loads. This script replaces anchor-only URLs with absolute ones.
3+
4+
document.addEventListener('DOMContentLoaded', () => {
5+
const links = document.querySelectorAll<HTMLLinkElement>('a[href^="#"]')
6+
7+
links.forEach((link) => {
8+
if (link.getAttribute('href')?.startsWith('#')) {
9+
link.href = `${document.baseURI}${link.getAttribute('href')}`
10+
}
11+
})
12+
})
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import 'tailwindcss' theme(static);
2-
@import './assets/typography.css';
3-
@import './assets/highlighting.css';
2+
@import './typography.css';
3+
@import './highlighting.css';
44

55
@custom-variant light (&:where(.light, .light *));
66
@custom-variant dark (&:where(.dark, .dark *));

src/Web/assets/main.entrypoint.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './register-fonts.ts'
2+
import './copy-code-blocks.ts'
3+
import './highlight-current-prose-title.ts'
4+
import './save-scroll.ts'
5+
import './fix-anchors.ts'

src/Web/main.entrypoint.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)