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

How do you stop prefix from prefixing the distDir? #239

Closed eight04 closed 2 years ago

eight04 commented 2 years ago

I want to build index.html as docs/index.html, while mounting the page in a subfolder.

If I set prefix to fancy-t-spin, the path will be resolved correctly:

<link rel="prefetch" href="/fancy-t-spin/_elderjs/svelte/components/Link.30b50837.js" as="script">

However, index.html will be built into docs/fancy-t-spin/index.html.

In https://github.com/Elderjs/elderjs/pull/128/files, it seems that there is a variable $$internal.serverPrefix but defining it in elder.config.js has no effect.

nickreese commented 2 years ago

The server prefix is added to all output files including the components, css, and html.

Something I have considered is allowing a customPrefix defined at the route level and adjusting how the prefix works in the wrapPremalinkFn.ts.

Another option is allowing a request object to have a permalink defined during a route's all function. This would bypass the use of the permalink function for the route.

The drawback to both of these is they undermine the usage of helpers.permalinks[routeName] in the templates which is something we use heavily and I can see lots of users using as well.

Open to continue this discussion. As I know some people have had issues hosting on gitlab due to this pattern of using the prefix on all files emitted.

eight04 commented 2 years ago

Currently I use a buildComplete hook moving files under ${distDir}/${prefix} back to distDir: https://github.com/eight04/fancy-t-spin/blob/e1a4085cc7ec608825ebfb9fe801b6f026d35feb/src/hooks.js#L27-L39