-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add option to prefix sitemap #9846
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
af73d5c
Add option to prefix sitemap
ktym4a 013bc8e
Fix call resolve twice
ktym4a b596506
let to const
ktym4a 4c6a69e
Apply suggestions from code review
ktym4a 21a2f02
Merge branch 'main' into add-sitemap-rename-option
ktym4a 1f192b1
change changeset patch to minor
ktym4a 76d7c3f
use node:test
ktym4a c0cd345
Update changeset
ktym4a 66f52bd
Add regex validation for prefix
ktym4a 1889d67
Update .changeset/eighty-falcons-tease.md
ktym4a 8d96f1a
Update prefix regex in SitemapOptionsSchema
ktym4a 902826f
Merge remote-tracking branch 'refs/remotes/origin/add-sitemap-rename-…
ktym4a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| "@astrojs/sitemap": minor | ||
| --- | ||
|
|
||
| Adds a new configuration option `prefix` that allows you to change the default `sitemap-*.xml` file name. | ||
|
|
||
| By default, running `astro build` creates both `sitemap-index.xml` and `sitemap-0.xml` in your output directory. | ||
|
|
||
| To change the names of these files (e.g. to `astrosite-index.xml` and `astrosite-0.xml`), set the `prefix` option in your `sitemap` integration configuration: | ||
|
|
||
| ``` | ||
| import { defineConfig } from 'astro/config'; | ||
| import sitemap from '@astrojs/sitemap'; | ||
| export default defineConfig({ | ||
| site: 'https://example.com', | ||
| integrations: [ | ||
| sitemap({ | ||
| prefix: 'astrosite-', | ||
| }), | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| This option is useful when you submit a sitemap to Google Search Console and the Status becomes `Cloudn't fetch` | ||
This file contains hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
| import { loadFixture, readXML } from './test-utils.js'; | ||
| import { sitemap } from './fixtures/static/deps.mjs'; | ||
| import assert from 'node:assert/strict'; | ||
| import { before, describe, it } from 'node:test'; | ||
|
|
||
| describe('Prefix support', () => { | ||
| /** @type {import('./test-utils.js').Fixture} */ | ||
| let fixture; | ||
| const prefix = 'test-'; | ||
|
|
||
| describe('Static', () => { | ||
| before(async () => { | ||
| fixture = await loadFixture({ | ||
| root: './fixtures/static/', | ||
| integrations: [ | ||
| sitemap(), | ||
| sitemap({ | ||
| prefix, | ||
| }), | ||
| ], | ||
| }); | ||
| await fixture.build(); | ||
| }); | ||
|
|
||
| it('Content is same', async () => { | ||
| const data = await readXML(fixture.readFile('/sitemap-0.xml')); | ||
| const prefixData = await readXML(fixture.readFile(`/${prefix}0.xml`)); | ||
| assert.deepEqual(prefixData, data); | ||
| }); | ||
|
|
||
| it('Index file load correct sitemap', async () => { | ||
| const data = await readXML(fixture.readFile('/sitemap-index.xml')); | ||
| const sitemapUrl = data.sitemapindex.sitemap[0].loc[0]; | ||
| assert.strictEqual(sitemapUrl, 'http://example.com/sitemap-0.xml'); | ||
|
|
||
| const prefixData = await readXML(fixture.readFile(`/${prefix}index.xml`)); | ||
| const prefixSitemapUrl = prefixData.sitemapindex.sitemap[0].loc[0]; | ||
| assert.strictEqual(prefixSitemapUrl, `http://example.com/${prefix}0.xml`); | ||
| }); | ||
| }); | ||
|
|
||
| describe('SSR', () => { | ||
| before(async () => { | ||
| fixture = await loadFixture({ | ||
| root: './fixtures/ssr/', | ||
| integrations: [ | ||
| sitemap(), | ||
| sitemap({ | ||
| prefix, | ||
| }), | ||
| ], | ||
| }); | ||
| await fixture.build(); | ||
| }); | ||
|
|
||
| it('Content is same', async () => { | ||
| const data = await readXML(fixture.readFile('/client/sitemap-0.xml')); | ||
| const prefixData = await readXML(fixture.readFile(`/client/${prefix}0.xml`)); | ||
| assert.deepEqual(prefixData, data); | ||
| }); | ||
|
|
||
| it('Index file load correct sitemap', async () => { | ||
| const data = await readXML(fixture.readFile('/client/sitemap-index.xml')); | ||
| const sitemapUrl = data.sitemapindex.sitemap[0].loc[0]; | ||
| assert.strictEqual(sitemapUrl, 'http://example.com/sitemap-0.xml'); | ||
|
|
||
| const prefixData = await readXML(fixture.readFile(`/client/${prefix}index.xml`)); | ||
| const prefixSitemapUrl = prefixData.sitemapindex.sitemap[0].loc[0]; | ||
| assert.strictEqual(prefixSitemapUrl, `http://example.com/${prefix}0.xml`); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.