awesome-docker/build.js

87 lines
2.0 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-03-18 09:37:19 -04:00
const critical = require('critical');
2018-03-17 11:27:41 -04:00
process.env.NODE_ENV = 'production';
2018-03-18 10:01:47 -04:00
const includeReadme = () => {
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,
splitAdjacentBlockquotes: true
});
// converter.setFlavor('github');
console.log('Loading files...');
const index = fs.readFileSync('website/index.tmpl.html', 'utf8');
const readme = fs.readFileSync('README.md', 'utf8');
console.log('Merging files...');
const $ = cheerio.load(index);
$('#md').append(converter.makeHtml(readme));
console.log('Writing index.html');
fs.writeFileSync('website/index.merged.html', $.html(), 'utf8');
2018-03-18 10:01:47 -04:00
return { base: 'website/', src: 'index.merged.html' };
};
2018-03-18 09:37:19 -04:00
2018-03-18 10:01:47 -04:00
const css = ({ base, src }) => {
2018-03-18 09:37:19 -04:00
console.log('');
console.log('Generating critical css above the fold');
console.log('');
2018-03-18 10:01:47 -04:00
const dimensions = [
{
height: 200,
width: 500
},
{
height: 900,
width: 1200
}
];
const options = {
inline: true,
base,
src,
dest: 'index.html',
dimensions
};
return critical.generate(options);
};
2018-03-18 09:37:19 -04:00
2018-03-18 10:01:47 -04:00
const bundle = () => {
console.log('');
console.log('Bundling with Parcel.js');
console.log('');
new Parcel('website/index.html', {
name: 'build',
publicURL: '/'
}).bundle();
};
2018-03-18 09:37:19 -04:00
2018-03-18 10:01:47 -04:00
const main = async () => {
const { base, src } = includeReadme();
await css({ base, src });
bundle();
2018-03-18 09:37:19 -04:00
};
main();