Skip to content
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

fix(core): throw error for invalid URL in config file #8159

Merged
merged 3 commits into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,6 +39,24 @@ describe('createSitemap', () => {
'URL in docusaurus.config.js cannot be empty/undefined.',
));

it('invalid URL', () =>
expect(async () => {
// @ts-expect-error: test
await createSitemap(
{
url: 'example.com',
forgeRW marked this conversation as resolved.
Show resolved Hide resolved
} as DocusaurusConfig,
['/', '/test'],
{},
{
changefreq: EnumChangefreq.DAILY,
priority: 0.7,
ignorePatterns: [],
filename: 'sitemap.xml',
},
);
}).rejects.toThrow('URL in docusaurus.config.js must be a valid URL.'));

it('exclusion of 404 page', async () => {
const sitemap = await createSitemap(
{
Expand Down
22 changes: 13 additions & 9 deletions packages/docusaurus-plugin-sitemap/src/createSitemap.ts
Expand Up @@ -77,16 +77,20 @@ export default async function createSitemap(

const sitemapStream = new SitemapStream({hostname});

includedRoutes.forEach((routePath) =>
sitemapStream.write({
url: applyTrailingSlash(routePath, {
trailingSlash: siteConfig.trailingSlash,
baseUrl: siteConfig.baseUrl,
try {
includedRoutes.forEach((routePath) =>
sitemapStream.write({
url: applyTrailingSlash(routePath, {
trailingSlash: siteConfig.trailingSlash,
baseUrl: siteConfig.baseUrl,
}),
changefreq,
priority,
}),
changefreq,
priority,
}),
);
);
} catch (err) {
throw new Error('URL in docusaurus.config.js must be a valid URL.');
}

sitemapStream.end();

Expand Down