Skip to content

Commit

Permalink
fix: normalize trailing slash in prerender (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Zerelles committed May 26, 2021
1 parent eb96322 commit 7934be9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/kit/src/core/adapt/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,26 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
}
});

/**
* @param {string} path
*/
function normalizeTrailingSlash(path) {
if (config.kit.trailingSlash === 'always') {
return path.endsWith('/') ? path : `${path}/`;
}
if (config.kit.trailingSlash === 'never') {
return !path.endsWith('/') || path === '/' ? path : path.slice(0, -1);
}
return path;
}

/**
* @param {string} path
* @param {string} parent
*/
async function visit(path, parent) {
path = normalizeTrailingSlash(path);

if (seen.has(path)) return;
seen.add(path);

Expand Down

0 comments on commit 7934be9

Please sign in to comment.