comments on prestart. added a package that should allow me to autogenerate nav for project docs

This commit is contained in:
len0rd 2018-08-05 13:06:18 -04:00
parent 2cf2bdf8ad
commit af215bca5d
3 changed files with 16 additions and 6 deletions

5
package-lock.json generated
View file

@ -118,6 +118,11 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
}, },
"dynamic-scrollspy": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/dynamic-scrollspy/-/dynamic-scrollspy-0.2.0.tgz",
"integrity": "sha512-MpzvxeGr8AjpbAF52Dfob926pImY7hwEA7HO5lfNsydZyGB5uS2oLGn/1NKoKkkxQ5VcLfua65RgNZYaFqIRgg=="
},
"ee-first": { "ee-first": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",

View file

@ -18,6 +18,7 @@
}, },
"homepage": "https://github.com/len0rd/personal-website#readme", "homepage": "https://github.com/len0rd/personal-website#readme",
"dependencies": { "dependencies": {
"dynamic-scrollspy": "^0.2.0",
"ejs": "^2.6.1", "ejs": "^2.6.1",
"express": "^4.16.3", "express": "^4.16.3",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",

View file

@ -11,13 +11,13 @@ const showdown = require('showdown'),
inputDir = './project_writeups/', inputDir = './project_writeups/',
outputDir = './views/partials/md/', outputDir = './views/partials/md/',
classMap = { classMap = {
h1: 'display-1' h1: 'display-1' //tag type : class to add to all tags of that type (class="display-1" added to all <h1>)
}; };
// handles adding classes to specific // handles adding classes to specific
// tag types automatically // tag types automatically
const addClass = { const addClass = {
type: 'output', type: 'output', // when it's triggered -> output is at the very end when text is html
filter: text => { filter: text => {
var modifiedText = text; var modifiedText = text;
Object.keys(classMap).forEach(function(key) { Object.keys(classMap).forEach(function(key) {
@ -25,7 +25,8 @@ const addClass = {
matcher = regex.exec(modifiedText); matcher = regex.exec(modifiedText);
while (matcher != null && !matcher[0].includes(classMap[key])) { while (matcher != null && !matcher[0].includes(classMap[key])) {
console.log(matcher[0]); // add the class content WHILE preserving any other properties already in the tag!
console.log("adding class content in: " + matcher[0]);
var restOfTag = matcher[1]; var restOfTag = matcher[1];
modifiedText = modifiedText.replace(matcher[0], `<${key} class="${classMap[key]}" ${restOfTag}>`); modifiedText = modifiedText.replace(matcher[0], `<${key} class="${classMap[key]}" ${restOfTag}>`);
@ -37,10 +38,12 @@ const addClass = {
} }
}; };
// create our Showdown converter with our custom extension
const converter = new showdown.Converter({ const converter = new showdown.Converter({
extensions: [addClass] extensions: [addClass]
}); });
// make the directory for our html output if necessary
mkdirp(outputDir, (err) => { mkdirp(outputDir, (err) => {
if (err) { if (err) {
console.error(err); console.error(err);
@ -49,6 +52,7 @@ mkdirp(outputDir, (err) => {
} }
}); });
// Lets start the actual conversion!
fs.readdir(inputDir, (err, files) => { fs.readdir(inputDir, (err, files) => {
files.forEach(file => { files.forEach(file => {
if (file.endsWith('.md')) { if (file.endsWith('.md')) {
@ -58,7 +62,7 @@ fs.readdir(inputDir, (err, files) => {
if (err) { if (err) {
console.error(err); console.error(err);
} else { } else {
let html = converter.makeHtml(data); let html = converter.makeHtml(data); // where the magic happens
fs.writeFile(outputDir + fileNameNoExtension + '.ejs', html, 'utf8', (err) => { fs.writeFile(outputDir + fileNameNoExtension + '.ejs', html, 'utf8', (err) => {
if (err) { if (err) {
console.error(err); console.error(err);