mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +02:00
feat(v2): generate sitemap (#1065)
* feat(v2): generate sitemap * cannot snapshot sitemap because xml generated in different order
This commit is contained in:
parent
8663a63e7d
commit
fd780f19a2
18 changed files with 127 additions and 1185 deletions
|
@ -4,4 +4,5 @@ module.exports = {
|
|||
organizationName: 'endiliey',
|
||||
projectName: 'sakura',
|
||||
baseUrl: '/sakura/',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -4,4 +4,5 @@ module.exports = {
|
|||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -5,4 +5,5 @@ module.exports = {
|
|||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
defaultLanguage: 'en',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -5,4 +5,5 @@ module.exports = {
|
|||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
defaultLanguage: 'en',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -4,4 +4,5 @@ module.exports = {
|
|||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
44
v2/test/core/sitemap.test.js
Normal file
44
v2/test/core/sitemap.test.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
import '@babel/polyfill';
|
||||
import createSitemap from '@lib/core/sitemap';
|
||||
import loadSetup from '../loadSetup';
|
||||
|
||||
describe('sitemap', () => {
|
||||
test('simple site', async () => {
|
||||
const props = await loadSetup('simple');
|
||||
const sitemap = await createSitemap(props);
|
||||
expect(sitemap).toContain(
|
||||
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
|
||||
);
|
||||
});
|
||||
|
||||
test('translated site', async () => {
|
||||
const props = await loadSetup('translated');
|
||||
const sitemap = await createSitemap(props);
|
||||
expect(sitemap).toContain(
|
||||
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
|
||||
);
|
||||
});
|
||||
|
||||
test('versioned site', async () => {
|
||||
const props = await loadSetup('versioned');
|
||||
const sitemap = await createSitemap(props);
|
||||
expect(sitemap).toContain(
|
||||
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
|
||||
);
|
||||
});
|
||||
|
||||
test('translated + versioned site', async () => {
|
||||
const props = await loadSetup('transversioned');
|
||||
const sitemap = await createSitemap(props);
|
||||
expect(sitemap).toContain(
|
||||
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
|
||||
);
|
||||
});
|
||||
|
||||
test('empty site', async () => {
|
||||
const props = await loadSetup('empty');
|
||||
expect(createSitemap(props)).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Url in siteConfig.js cannot be empty/undefined"`,
|
||||
);
|
||||
});
|
||||
});
|
|
@ -4,4 +4,5 @@ module.exports = {
|
|||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -5,4 +5,5 @@ module.exports = {
|
|||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
defaultLanguage: 'en',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -5,4 +5,5 @@ module.exports = {
|
|||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
defaultLanguage: 'en',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -4,4 +4,5 @@ module.exports = {
|
|||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -8,4 +8,5 @@ module.exports = {
|
|||
superman: 'lol',
|
||||
admin: 'endi',
|
||||
customFields: ['admin', 'superman'],
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
|
|
|
@ -5,15 +5,18 @@ describe('loadConfig', () => {
|
|||
test('website with valid siteConfig', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
|
||||
const config = loadConfig(siteDir);
|
||||
expect(config).toEqual({
|
||||
baseUrl: '/',
|
||||
organizationName: 'endiliey',
|
||||
customDocsPath: 'docs',
|
||||
docsUrl: 'docs',
|
||||
projectName: 'hello',
|
||||
tagline: 'Hello World',
|
||||
title: 'Hello',
|
||||
});
|
||||
expect(config).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"baseUrl": "/",
|
||||
"customDocsPath": "docs",
|
||||
"docsUrl": "docs",
|
||||
"organizationName": "endiliey",
|
||||
"projectName": "hello",
|
||||
"tagline": "Hello World",
|
||||
"title": "Hello",
|
||||
"url": "https://docusaurus.io",
|
||||
}
|
||||
`);
|
||||
expect(config).not.toEqual({});
|
||||
});
|
||||
|
||||
|
@ -22,7 +25,7 @@ describe('loadConfig', () => {
|
|||
expect(() => {
|
||||
loadConfig(siteDir);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"tagline, organizationName, projectName fields are missing in siteConfig.js"`,
|
||||
`"tagline, organizationName, projectName, url fields are missing in siteConfig.js"`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -40,7 +43,7 @@ describe('loadConfig', () => {
|
|||
expect(() => {
|
||||
loadConfig(siteDir);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"title, tagline, organizationName, projectName, baseUrl fields are missing in siteConfig.js"`,
|
||||
`"title, tagline, organizationName, projectName, baseUrl, url fields are missing in siteConfig.js"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue