Elderjs / elderjs

Elder.js is an opinionated static site generator and web framework for Svelte built with SEO in mind.
https://elderguide.com/tech/elderjs/
MIT License
2.11k stars 53 forks source link

Permalink with accents : inconsistency between dev and build #116

Open kiuKisas opened 3 years ago

kiuKisas commented 3 years ago

Let's say I have a permalink with an accent, for exemple /salamèche. In dev mode, when I try to access the page, I get a Not Found page. When I build, I get the correct path salamèche in my public folder and I can access the page as expected.

I tried to wrap my permalink with encodeURI function. It work now in dev mode, when I build, it create the folder salam%C3%A8che but I can't access this page (with sirv-cli), either with /salamèche or /salam%C3%A8che.

Elderjs: 1.2.4
Svelte: 3.29.0
kiuKisas commented 3 years ago

A quick fix will be to add encodeURI to permalink in dev mode, but it doesn't feel right as it can prevent some error in permalink to show in dev mode but will be there in build mode. I guess it as something to do with polka configuration..

nickreese commented 3 years ago

I'll ping @lukeed about what Polka may be doing.

lukeed commented 3 years ago

Hey,

I'm assuming that @kiuKisas started with the template. If so, that's using polka@0.5.2 which does not decode URLs by default. This was changed within polka@next. You can change this by installing and attaching @polka/url@next, which also happens to be the same parser that sirv uses. Here's the how-to

Beyond that, I would need some kind of minimal repro to see what (else?) is going on as I'm unfortunately not super familiar with all the moving pieces here

lukeed commented 3 years ago

Just to confirm – that should be the fix since Polka is setting req.path which sirv then respects & uses, preventing its own decode.

Your directory name should contain the special characters. It worked in dev because your filesystem also contained the special characters, but the in-memory FILES cache of sirv possessed keys like /salamèche, but the req.path was sending the still-encoded /salam%C3%A8che form.

kiuKisas commented 3 years ago

I had more time to try it out, and it works indeed ! Just to recap if someone need it right now, this is the way to go: