-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sitemap): url when rest parameter is used in page file names (#9975)
* fix(sitemap): url when rest parameter is used in page file names * Update .changeset/sour-ties-sparkle.md Co-authored-by: Florian Lefebvre <[email protected]> * Apply suggestions from code review --------- Co-authored-by: Florian Lefebvre <[email protected]> Co-authored-by: Emanuele Stoppa <[email protected]>
- Loading branch information
1 parent
9001d06
commit ec7d2eb
Showing
7 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@astrojs/sitemap": patch | ||
--- | ||
|
||
Fixes URL generation for routes that rest parameters and start with `/` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {before, describe, it} from "node:test"; | ||
import {loadFixture, readXML} from "./test-utils.js"; | ||
import assert from "node:assert/strict"; | ||
|
||
describe('Dynamic with rest parameter', () => { | ||
/** @type {import('./test-utils.js').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/dynamic', | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('Should generate correct urls', async () => { | ||
const data = await readXML(fixture.readFile('/sitemap-0.xml')); | ||
const urls = data.urlset.url.map((url) => url.loc[0]); | ||
|
||
assert.ok(urls.includes('http://example.com/')); | ||
assert.ok(urls.includes('http://example.com/blog/')); | ||
assert.ok(urls.includes('http://example.com/test/')); | ||
}); | ||
}) |
7 changes: 7 additions & 0 deletions
7
packages/integrations/sitemap/test/fixtures/dynamic/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import sitemap from '@astrojs/sitemap'; | ||
|
||
export default defineConfig({ | ||
integrations: [sitemap()], | ||
site: 'http://example.com' | ||
}) |
9 changes: 9 additions & 0 deletions
9
packages/integrations/sitemap/test/fixtures/dynamic/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/sitemap-dynamic", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/sitemap": "workspace:*" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/integrations/sitemap/test/fixtures/dynamic/src/pages/[...slug].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
return [ | ||
{ | ||
params: { | ||
slug: undefined, | ||
} | ||
}, | ||
{ | ||
params: { | ||
slug: '/blog' | ||
} | ||
}, | ||
{ | ||
params: { | ||
slug: '/test' | ||
} | ||
} | ||
]; | ||
} | ||
--- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.