aboutsummaryrefslogtreecommitdiff
path: root/save-index.js
diff options
context:
space:
mode:
Diffstat (limited to 'save-index.js')
-rw-r--r--save-index.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/save-index.js b/save-index.js
new file mode 100644
index 0000000..b914eb6
--- /dev/null
+++ b/save-index.js
@@ -0,0 +1,37 @@
+const ejs = require("ejs");
+const fs = require("fs");
+
+function saveIndex(articles, outputFile, title, banner) {
+ articles.sort((a, b) => {
+ return (b.rawDate || 0) - (a.rawDate || 0);
+ });
+
+ return new Promise((resolve, reject) => {
+ fs.readFile("templates/index.ejs", (err, data) => {
+ if (err) { return reject(err); }
+
+ const indexBodyHTML = ejs.render(data.toString(), {
+ articles: articles.filter(article => {
+ return !article.hidden;
+ }),
+ banner,
+ });
+
+ fs.readFile("templates/layout.ejs", (err, data) => {
+ const indexHTML = ejs.render(data.toString(), {
+ title: title || "blog | fuwn",
+ description: "fuwn, a naritive through my struggles",
+ body: indexBodyHTML,
+ });
+
+ fs.writeFile(outputFile, indexHTML, err => {
+ if (err) { return reject(err); }
+
+ resolve("ok!");
+ });
+ });
+ });
+ });
+}
+
+module.exports = saveIndex;