docusaurus/v2/lib/core/sitemap.js
Yangshun Tay 7dae4bd0d1
chore: rename siteConfig.js to docusaurus.config.js (#1245)
* chore: rename siteConfig.js to docusaurus.config.js

* Prettier
2019-02-23 11:16:24 -08:00

45 lines
943 B
JavaScript

/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
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 docusaurus.config.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();
};