Skip to content
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] render routes ending with .html.svelte to html files #1939

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/kit/src/core/adapt/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
*/
function normalize(path) {
if (config.kit.trailingSlash === 'always') {
return path.endsWith('/') ? path : `${path}/`;
return path.endsWith('/') || path.endsWith('.html') ? path : `${path}/`;
Copy link
Member

@benmccann benmccann Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just .html? What if the user wants to generate a sitemap.xml from sitemap.xml.svelte?

always no longer feels like a good name for this since it's not always doing it

This sort of feels like it should accept a function to let the user decide like #2008 and #2007. Then you could have it do whatever you want

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Svelte files are designed to compose components made with HTML/CSS/JS so users won't generate files other than .html file, I think.

But endpoints like sitemap.xml.js are considered, so I think this option should be changed, as you say.

Can I change this option to something like never | ignore | (path: string) => boolean , in this PR? Or do you think it would be better to change it as a separate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right that you'd use an endpoint

This probably shouldn't be a function after all. It gets stringified during build and could be confusing to users

I think a better logic here might be to do it only if the last path segment does not contain ., but let me ask the other maintainers what they think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that might not be a great solution either. E.g. that wouldn't work with the URL https://bundlephobia.com/package/svelte@3.42.1

I think we just leave this as is and say you should not use the option always if you're generating .html files

} else if (config.kit.trailingSlash === 'never') {
return !path.endsWith('/') || path === '/' ? path : path.slice(0, -1);
}
Expand Down Expand Up @@ -143,7 +143,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
const is_html = response_type === REDIRECT || type === 'text/html';

const parts = path.split('/');
if (is_html && parts[parts.length - 1] !== 'index.html') {
if (is_html && !parts[parts.length - 1].endsWith('.html')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this need to change? if you encounter about.html why are you pushing index.html?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, paths like **/about.html are modified to **/about.html/index.html so I changed not to do so.

parts.push('index.html');
}

Expand Down Expand Up @@ -172,7 +172,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
const is_html = result.headers['content-type'] === 'text/html';

const parts = dependency_path.split('/');
if (is_html && parts[parts.length - 1] !== 'index.html') {
if (is_html && !parts[parts.length - 1].endsWith('.html')) {
parts.push('index.html');
}

Expand Down
Empty file.
4 changes: 2 additions & 2 deletions packages/kit/src/core/adapt/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ suite('prerender', async () => {
};

/** @type {import('types/internal').BuildData} */
const build_data = { client: [], server: [], static: [], entries: ['/nested'] };
const build_data = { client: [], server: [], static: [], entries: ['/nested', '/about.html'] };

const utils = get_utils({ cwd, config, build_data, log });

Expand All @@ -103,7 +103,7 @@ suite('prerender', async () => {
dest
});

assert.equal(glob('**', { cwd: `${prerendered_files}` }), glob('**', { cwd: dest }));
assert.equal(glob('**', { cwd: `${prerendered_files}` }), glob('**', { cwd: dest, flush: true }));

rimraf.sync(dest);
});
Expand Down