diff --git a/src/build.js b/src/build.js index 7a66463..4acee5c 100644 --- a/src/build.js +++ b/src/build.js @@ -2,7 +2,7 @@ const { exec } = require("child_process"); const buildFolder = "build" - +const articleFolder = "src/article" console.log("clearing the build folder..."); @@ -13,3 +13,35 @@ console.log("linking static files..."); exec(`ls src/static | while read in; do ln ../src/static/$in ${buildFolder} -s; done`) + +console.log("reading article files..."); +const articleEntries = fs.readdirSync(articleFolder).reduce((o, fileName) => ({ + ...o, + [fileName.replace(".md", "")]: fs.readFileSync(`${articleFolder}/${fileName}`, 'utf8').split("\n") +}), {}); + +for (const [name, data] of Object.entries(articleEntries)) { + data.forEach((line, index) => { + for (var i = 1; i < 5; i++) { + const headerStart = `${"#".repeat(i)} ` + if (line.startsWith(headerStart)) { + line = `${line.substring(i+1)}` + data[index] = line; + } + } + }); +} + +console.log("processing article entries..."); +for (const [name, data] of Object.entries(articleEntries)) { + articleEntries[name] = data.join("\n"); +} + + +console.log("loading template..."); +const template = fs.readFileSync('src/template.html', 'utf8'); + +console.log("writing articles..."); +for (const [name, data] of Object.entries(articleEntries)) { + fs.writeFile(`${buildFolder}/${name}.html`, template.replace("", data), (error) => {}); +} diff --git a/src/build.js b/src/build.js index 7a66463..4acee5c 100644 --- a/src/build.js +++ b/src/build.js @@ -2,7 +2,7 @@ const { exec } = require("child_process"); const buildFolder = "build" - +const articleFolder = "src/article" console.log("clearing the build folder..."); @@ -13,3 +13,35 @@ console.log("linking static files..."); exec(`ls src/static | while read in; do ln ../src/static/$in ${buildFolder} -s; done`) + +console.log("reading article files..."); +const articleEntries = fs.readdirSync(articleFolder).reduce((o, fileName) => ({ + ...o, + [fileName.replace(".md", "")]: fs.readFileSync(`${articleFolder}/${fileName}`, 'utf8').split("\n") +}), {}); + +for (const [name, data] of Object.entries(articleEntries)) { + data.forEach((line, index) => { + for (var i = 1; i < 5; i++) { + const headerStart = `${"#".repeat(i)} ` + if (line.startsWith(headerStart)) { + line = `${line.substring(i+1)}` + data[index] = line; + } + } + }); +} + +console.log("processing article entries..."); +for (const [name, data] of Object.entries(articleEntries)) { + articleEntries[name] = data.join("\n"); +} + + +console.log("loading template..."); +const template = fs.readFileSync('src/template.html', 'utf8'); + +console.log("writing articles..."); +for (const [name, data] of Object.entries(articleEntries)) { + fs.writeFile(`${buildFolder}/${name}.html`, template.replace("", data), (error) => {}); +} diff --git a/src/template.html b/src/template.html index 49c6512..5cbbb40 100644 --- a/src/template.html +++ b/src/template.html @@ -9,6 +9,7 @@ +