awesome-docker/build.js

99 lines
2.6 KiB
Markdown
Raw Normal View History

2018-03-17 11:27:41 -04:00
const fs = require('fs');
const showdown = require('showdown');
const cheerio = require('cheerio');
const Parcel = require('parcel-bundler');
2018-06-09 16:59:45 -04:00
const sm = require('sitemap');
2018-03-17 11:27:41 -04:00
process.env.NODE_ENV = 'production';
2018-04-07 08:38:24 -04:00
process.on('unhandledRejection', error => {
console.log('unhandledRejection', error.message);
});
const readme = 'README.md';
const template = 'website/index.tmpl.html';
const merged = 'website/index.html';
const destination = 'website/index.html';
const includeReadme = ({
md = readme,
templateHTML = template,
dest = merged,
2018-06-08 13:38:46 -04:00
} = {}) => {
2018-03-18 09:37:19 -04:00
const converter = new showdown.Converter({
omitExtraWLInCodeBlocks: true,
simplifiedAutoLink: true,
excludeTrailingPunctuationFromURLs: true,
literalMidWordUnderscores: true,
strikethrough: true,
tables: true,
tablesHeaderId: true,
ghCodeBlocks: true,
tasklists: true,
disableForced4SpacesIndentedSublists: true,
simpleLineBreaks: true,
requireSpaceBeforeHeadingText: true,
ghCompatibleHeaderId: true,
ghMentions: true,
backslashEscapesHTMLTags: true,
emoji: true,
2018-04-07 08:38:24 -04:00
splitAdjacentBlockquotes: true,
2018-03-18 09:37:19 -04:00
});
// converter.setFlavor('github');
console.log('Loading files...');
2018-04-07 08:38:24 -04:00
const indexTemplate = fs.readFileSync(templateHTML, 'utf8');
const markdown = fs.readFileSync(md, 'utf8');
2018-03-18 09:37:19 -04:00
console.log('Merging files...');
2018-04-07 08:38:24 -04:00
const $ = cheerio.load(indexTemplate);
$('#md').append(converter.makeHtml(markdown));
2018-03-18 09:37:19 -04:00
console.log('Writing index.html');
2018-04-07 08:38:24 -04:00
fs.writeFileSync(dest, $.html(), 'utf8');
console.log('DONE 👍');
2018-03-18 10:01:47 -04:00
};
2018-03-18 09:37:19 -04:00
2018-04-07 08:38:24 -04:00
const bundle = (dest = destination) => {
2018-03-18 10:01:47 -04:00
console.log('');
console.log('Bundling with Parcel.js');
console.log('');
2018-04-07 08:38:24 -04:00
new Parcel(dest, {
2018-03-18 10:01:47 -04:00
name: 'build',
2018-04-07 08:38:24 -04:00
publicURL: '/',
2018-04-22 06:34:38 -04:00
})
.bundle()
.then(() => {
2018-06-09 16:59:45 -04:00
// Creates a sitemap object given the input configuration with URLs
const sitemap = sm.createSitemap({
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',
},
{
url: '/table.html',
changefreq: 'weekly',
priority: 0.8,
lastmodrealtime: true,
lastmodfile: 'dist/table.html',
},
],
});
fs.writeFileSync('dist/sitemap.xml', sitemap.toString());
// fs.copyFileSync('website/sitemap.xml', 'dist/sitemap.xml');
2018-04-22 06:34:38 -04:00
});
2018-03-18 10:01:47 -04:00
};
2018-03-18 09:37:19 -04:00
2018-04-07 08:38:24 -04:00
const main = () => {
2018-06-08 13:38:46 -04:00
includeReadme();
2018-03-18 10:01:47 -04:00
bundle();
2018-03-18 09:37:19 -04:00
};
main();