1
1
Fork 0

Markdown rendering readme

This commit is contained in:
Joe Wroten 2018-12-27 08:21:25 -06:00
parent 589792d315
commit 0bd62c6b16
3 changed files with 20 additions and 2 deletions

View file

@ -1,3 +1,4 @@
const marked = require('marked');
const { compile } = require('handlebars');
const requestGithub = require('./src/request');
const { join } = require('path');
@ -8,6 +9,9 @@ const dist = './dist';
const exampleHBS = compile(`
<h1>{{name}}</h1>
<hr />
<main>
{{{readme.html}}}
</main>
`);
(async () => {
@ -45,7 +49,14 @@ const exampleHBS = compile(`
let combinedJSONs = filesJSON.concat(pinnedRepoData);
let writeFilesPromises = combinedJSONs.map(json => {
let renderReadmes = combinedJSONs.map(json => {
if (json.readme && json.readme.text) {
json.readme.html = marked(json.readme.text);
}
return json;
});
let writeFilesPromises = renderReadmes.map(json => {
let fileName = json.name.replace(/[^a-zA-Z\d:]/g, '').toLowerCase();
return outputFile(join(dist, fileName) + '.html', exampleHBS(json));
});

6
package-lock.json generated
View file

@ -97,6 +97,12 @@
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==",
"dev": true
},
"marked": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/marked/-/marked-0.5.2.tgz",
"integrity": "sha512-fdZvBa7/vSQIZCi4uuwo2N3q+7jJURpMVCcbaX0S1Mg65WZ5ilXvC67MviJAsdjqqgD+CEq4RKo5AYGgINkVAA==",
"dev": true
},
"minimist": {
"version": "0.0.10",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",

View file

@ -6,6 +6,7 @@
"devDependencies": {
"axios": "^0.18.0",
"fs-extra": "^7.0.1",
"handlebars": "^4.0.12"
"handlebars": "^4.0.12",
"marked": "^0.5.2"
}
}