fix sitemap build step

This commit is contained in:
Julien Bisconti 2020-03-08 13:45:52 +01:00
parent 2f47b5dbe4
commit 2917fe08a7
No known key found for this signature in database
GPG Key ID: 62772C6698F736CB
2 changed files with 19 additions and 18 deletions

View File

@ -2,7 +2,8 @@ const fs = require('fs-extra');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
const showdown = require('showdown'); const showdown = require('showdown');
const Parcel = require('parcel-bundler'); const Parcel = require('parcel-bundler');
const sm = require('sitemap'); // const sm = require('sitemap');
const { SitemapStream, streamToPromise } = require('sitemap');
process.env.NODE_ENV = 'production'; process.env.NODE_ENV = 'production';
@ -25,20 +26,6 @@ const WEBSITE_FOLDER = 'website';
const indexTemplate = `${WEBSITE_FOLDER}/index.tmpl.html`; const indexTemplate = `${WEBSITE_FOLDER}/index.tmpl.html`;
const indexDestination = `${WEBSITE_FOLDER}/index.html`; const indexDestination = `${WEBSITE_FOLDER}/index.html`;
const sitemapOpts = {
hostname: 'https://awesome-docker.netlify.com/',
cacheTime: 6000000, // 600 sec (10 min) cache purge period
urls: [
{
url: '/',
changefreq: 'daily',
priority: 0.8,
lastmodrealtime: true,
lastmodfile: 'dist/index.html',
},
],
};
async function processIndex() { async function processIndex() {
const converter = new showdown.Converter({ const converter = new showdown.Converter({
omitExtraWLInCodeBlocks: true, omitExtraWLInCodeBlocks: true,
@ -88,11 +75,25 @@ const bundle = () => {
publicURL: '/', publicURL: '/',
}) })
.bundle() .bundle()
.then(() => .then(() => {
const smStream = new SitemapStream({ hostname: 'https://awesome-docker.netlify.com/' });
smStream.write({
url: '/',
changefreq: 'daily',
priority: 0.8,
lastmodrealtime: true,
lastmodfile: 'dist/index.html',
});
smStream.end();
return streamToPromise(smStream);
})
.then(sm =>
// Creates a sitemap object given the input configuration with URLs // Creates a sitemap object given the input configuration with URLs
fs.outputFile( fs.outputFile(
'dist/sitemap.xml', 'dist/sitemap.xml',
sm.createSitemap(sitemapOpts).toString(), // sm.createSitemap(sitemapOpts).toString(),
sm.toString()
), ),
); );
}; };