awesome-docker/build.js

90 lines
2.1 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-04-22 07:51:56 -04:00
const camelCase = require('camelcase');
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-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-04-22 07:51:56 -04:00
$('a').each((i, elem) => {
$(elem).attr(
'id',
2018-04-22 08:39:58 -04:00
camelCase(
2018-04-22 07:51:56 -04:00
$(elem)
.attr('href')
.replace(/\/|\.|:|#/g, ''),
{
pascalCase: true,
},
2018-04-22 08:39:58 -04:00
),
2018-04-22 07:51:56 -04:00
);
});
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(() => {
fs.copyFileSync('website/sitemap.xml', 'dist/sitemap.xml');
});
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 = () => {
includeReadme({});
2018-03-18 10:01:47 -04:00
bundle();
2018-03-18 09:37:19 -04:00
};
main();