6ff3a63a2e
Avoid trailing slashes on urls that look like files. The redirect for `trailingSlash: true` will now look like: ``` Redirects ┌ source: /:path*/:file.:ext/ ├ destination: /:path*/:file.:ext └ permanent: true ┌ source: /:path*/:notfile([^/.]+) ├ destination: /:path*/:notfile/ └ permanent: true ``` The default still looks like: ``` Redirects ┌ source: /:path+/ ├ destination: /:path+ └ permanent: true ``` After this gets merged, I have a few optimizations planned on the normalization code that should reduce the client bundle a little and that consolidates the `trailingSlash` and `exportTrailingSlash` options
20 lines
437 B
TypeScript
20 lines
437 B
TypeScript
export function normalizeTrailingSlash(
|
|
path: string,
|
|
requireSlash?: boolean
|
|
): string {
|
|
if (requireSlash) {
|
|
if (!path.endsWith('/') && !/\.[^/]+$/.test(path)) {
|
|
return path + '/'
|
|
} else if (/\.[^/]+\/$/.test(path)) {
|
|
return path.slice(0, -1)
|
|
} else {
|
|
return path
|
|
}
|
|
} else {
|
|
if (path.endsWith('/') && path !== '/') {
|
|
return path.slice(0, -1)
|
|
} else {
|
|
return path
|
|
}
|
|
}
|
|
}
|