-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] customizable output file names for prerendering #2276
Conversation
🦋 Changeset detectedLatest commit: 90c596d The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
adapter-static
adapter-static
@@ -0,0 +1,38 @@ | |||
# create-svelte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we test this feature using an existing test project? we try to minimize the number of test projects we create in order to avoid time starting / stopping the server, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea how to test in one project using two different adapter options. The structure of build dir is totally different with or without this option. May be we can use subdir to split different strategies?
routes
├── default
│ ├── index.svelte
│ └── sub
│ └── page.svelte
└── strip-index
├── index.svelte
└── sub
└── page.svelte
outputFileName: ({ path, is_html }) => {
if (!is_html) return path;
if (path.startsWith('/strip-index/')) {
// return custom name
}
// return default name
}
According to the coding style guidelines, renamed API option name and use deconstruction of object as argument. |
packages/adapter-static/README.md
Outdated
|
||
A optional function that is called per entry to return the destination to write to. | ||
|
||
Default value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than include the code here, I would describe it textually like:
By default, prerendered html pages are output as
index.html
files in the directory matching the URL path.
And then maybe show an example of doing something else with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this one:
outputFileName
A optional function that is called per entry to return the destination to write to.
By default, prerendered html pages are output as index.html files in the directory matching the URL path.
URL | output file |
---|---|
/ | /index.html |
/foo | /foo/index.html |
/bar.html | /bar.html/index.html |
/foo/bar | /foo/bar/index.html |
For example, you may prefer /foo.html
to /foo/index.html
:
import { format, parse } from 'path';
outputFileName: ({ path, is_html }) => {
if (!is_html) return path;
let { root, dir, name, ext } = parse(path);
if (!ext) ext = '.html';
return format({ root, dir, name, ext });
}
It looks like |
@@ -38,6 +38,25 @@ The directory to write static assets (the contents of `static`, plus client-side | |||
|
|||
Specify a fallback page for SPA mode, e.g. `index.html` or `200.html` or `404.html`. | |||
|
|||
### outputFileName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect a new option to go with the pre-rendering options. There's nothing specific about adapter-static
to it
Thank you for this PR. I discussed it with the rest of the maintainers at today's maintainer's meeting and the thought was that we should just add a I really appreciate all the work that you've done on this. I'm going to go ahead and close it though given the feedback from the maintainers group. I'd be happy to consider a PR for the |
Usage: ```json kit: { prerender: { subfolders: false, }, ``` Setting the kit.prerender.subfolders setting to false (default is true) will change the filename generation from "/about/index.html" to "/about.html" Inspiration for the `subfolders` name came from nuxt: https://nuxtjs.org/docs/configuration-glossary/configuration-generate/#subfolders - Fixes sveltejs#1443, - Related to sveltejs#2276, [sapper/sveltejs#1021](sveltejs/sapper#1021)
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0Ref #1443
This PR provide an optional callback to custom entry names for adapter-static.
Example:
blog/hello-world.html.svelte
=>blog/hello-world.html
about.svelte
=>about.html