Skip to content

Commit c04e1ac

Browse files
committed
fix: fix sitemap trailing slash (with tests)
1 parent fba2d24 commit c04e1ac

File tree

15 files changed

+176
-30
lines changed

15 files changed

+176
-30
lines changed

.changeset/wise-panthers-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@blinkk/root': patch
3+
---
4+
5+
fix: fix sitemap trailing slash (with tests)

packages/root/src/render/router.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export class Router {
105105
return [];
106106
}
107107

108+
const trailingSlash = this.rootConfig.server?.trailingSlash;
109+
108110
const urlPaths: Array<{urlPath: string; params: Record<string, string>}> =
109111
[];
110112
if (routeModule.getStaticPaths) {
@@ -124,7 +126,7 @@ export class Router {
124126
);
125127
} else {
126128
urlPaths.push({
127-
urlPath: normalizeUrlPath(urlPath),
129+
urlPath: normalizeUrlPath(urlPath, {trailingSlash}),
128130
params: pathParams.params || {},
129131
});
130132
}

packages/root/test/asset-url-format.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path';
22
import {beforeEach, test, expect, afterEach} from 'vitest';
3-
import {listFilesRecursive} from '../src/utils/fsutils';
4-
import {Fixture, loadFixture} from './testutils';
3+
import {listFilesRecursive} from '../src/utils/fsutils.js';
4+
import {Fixture, loadFixture} from './testutils.js';
55

66
let fixture: Fixture;
77

packages/root/test/css-topsort.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import {promises as fs} from 'node:fs';
22
import path from 'node:path';
3-
43
import {assert, beforeEach, test, expect, afterEach} from 'vitest';
5-
6-
import {fileExists} from '../src/utils/fsutils';
7-
8-
import {Fixture, loadFixture} from './testutils';
4+
import {fileExists} from '../src/utils/fsutils.js';
5+
import {Fixture, loadFixture} from './testutils.js';
96

107
let fixture: Fixture;
118

packages/root/test/elements.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import {promises as fs} from 'node:fs';
22
import path from 'node:path';
3-
43
import {assert, beforeEach, test, expect, afterEach} from 'vitest';
5-
6-
import {fileExists} from '../src/utils/fsutils';
7-
8-
import {Fixture, loadFixture} from './testutils';
4+
import {fileExists} from '../src/utils/fsutils.js';
5+
import {Fixture, loadFixture} from './testutils.js';
96

107
let fixture: Fixture;
118

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
sitemap: true,
3+
domain: 'https://www.example.com',
4+
i18n: {
5+
urlPath: '/intl/[path]',
6+
locales: ['en', 'de', 'fr'],
7+
},
8+
server: {
9+
trailingSlash: true,
10+
},
11+
};

packages/root/test/fixtures/sitemap/routes/404.tsx

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default function Page(props: {slug: string}) {
2+
return <h1>Hello, {props.slug}!!</h1>;
3+
}
4+
5+
export async function getStaticPaths() {
6+
return {
7+
paths: [{params: {page: 'bar'}}, {params: {page: 'baz'}}],
8+
};
9+
}
10+
11+
export async function getStaticProps(ctx) {
12+
return {props: {slug: ctx.params.page}};
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <h1>Hello, foo!</h1>;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <h1>Hello, index!</h1>;
3+
}

0 commit comments

Comments
 (0)