feat(v2): generate sitemap (#1065)

* feat(v2): generate sitemap

* cannot snapshot sitemap because xml generated in different order
This commit is contained in:
Endilie Yacop Sucipto 2018-10-25 21:47:13 +08:00 committed by GitHub
parent 8663a63e7d
commit fd780f19a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 127 additions and 1185 deletions

38
v2/lib/core/sitemap.js Normal file
View file

@ -0,0 +1,38 @@
const sitemap = require('sitemap');
module.exports = async function createSitemap({
siteConfig = {},
docsMetadatas = {},
pagesMetadatas = [],
blogMetadatas = [],
}) {
const allMetadatas = [
...blogMetadatas,
...Object.values(docsMetadatas),
...pagesMetadatas,
];
const {url: siteUrl} = siteConfig;
if (!siteUrl) {
throw new Error('Url in siteConfig.js cannot be empty/undefined');
}
const urls = [];
allMetadatas.forEach(metadata => {
urls.push({
url: metadata.permalink,
changefreq: 'weekly',
priority: 0.5,
});
});
const sm = sitemap.createSitemap({
hostname: siteUrl,
cacheTime: 600 * 1000, // 600 sec - cache purge period
urls,
});
return sm.toString();
};