delan / autost

cohost-compatible blog engine and feed reader
ISC License
25 stars 1 forks source link

<base href> breaks fragment links #17

Closed delan closed 1 month ago

delan commented 1 month ago

the threads page template uses <base href>, but this breaks fragment links in posts.

for example, say you’re in /posts/1.html and you have:

<base href="/posts/">
<a href="#user-content-usb3sun-user-guide">

that becomes this, which may work but will navigate for no reason:

<a href="/posts/#user-content-usb3sun-user-guide">
delan commented 1 month ago

option 1: use js to fix fragment links from #foo to url#foo

option 2: opt-in fix with a {{ |url }} filter

option 3: magic fix

delan commented 1 month ago

if we go with a magic fix, what kinds of urls do we fix? say we have base_url = "/posts/"

if we fix this →
then we link to this ↓ with
/path/to/file only path/to/file only both
/posts/2.html /2.html 2.html either
/cats/diffie [../]../cats/diffie :(
//host/cats/diffie :(
/cats/diffie [../]../cats/diffie :(
//host/cats/diffie :(
/posts/tagged/cats.html /tagged/cats.html tagged/cats.html either

if we fix /path/to/file urls only…

current url →
link url ↓
/posts/1.html /posts/tagged/cats.html
2.html /posts/2.html \o/ /posts/tagged/2.html :(
/2.html /posts/2.html \o/ /posts/2.html \o/
/cats/diffie /posts/cats/diffie :( /posts/cats/diffie :(

if we fix path/to/file urls only…

current url →
link url ↓
/posts/1.html /posts/tagged/cats.html
2.html /posts/2.html \o/ /posts/2.html \o/
/2.html /2.html :( /2.html :(
/cats/diffie /cats/diffie \o/ /cats/diffie \o/

if we fix both…

current url →
link url ↓
/posts/1.html /posts/tagged/cats.html
2.html /posts/2.html \o/ /posts/2.html \o/
/2.html /posts/2.html \o/ /posts/2.html \o/
/cats/diffie /posts/cats/diffie :( /posts/cats/diffie :(
delan commented 1 month ago

you know your change is Good when it even “fixes” a couple of fucked up chosts :)

image

delan commented 1 month ago

fixed in d14767d0fe1ab13e01ec827cecdc4348d7331fda through f5415d8312a7e096109448e33010f6ef5bb30d31; 4e484df4221efb980741d2299bbc4ce31bb9d936 unfortunately comes with a pretty big perf regression, but i’ve managed to reclaim most of the runtime in subsequent commits: