From a3bc5c5231c476180651aa596ba4aa50fc878290 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 9 Apr 2021 17:34:02 +0430 Subject: a simple node express ejs blog --- css/master.css | 25 +++++++++++++++++++++++++ server.js | 39 +++++++++++++++++++++++++++++++++++++++ views/index.ejs | 18 ++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 css/master.css create mode 100755 server.js create mode 100644 views/index.ejs diff --git a/css/master.css b/css/master.css new file mode 100644 index 0000000..69d862e --- /dev/null +++ b/css/master.css @@ -0,0 +1,25 @@ +body{$ + font-family: "DejaVuSansMono NF", Helvetica, monospace; + color: #005f87; + background: #000000; + /* linear-gradient( */ + /* rgba(68, 68, 68, 1), */ + /* rgba(0, 0, 0, 1) */ + /* ); */ + text-align: left; + padding: 20px; + border-style: solid; +} + +.sidenav { + color: #00afd7; + height: 100%; + width: 160px; + position: fixed; + z-index: 1; + top: 0; + left: 0; + background-color: #111; + overflow-x: hidden; + padding-top: 20px; +} diff --git a/server.js b/server.js new file mode 100755 index 0000000..eaf1ac5 --- /dev/null +++ b/server.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node +"use strict"; + +const express = require("express"); +const path = require("path"); +const fs = require("fs"); +const mitTexMath = require("markdown-it-texmath"); +const mitMulMd = require("markdown-it-multimd-table"); +const mit = require("markdown-it")({ html: true }) + .enable(["table"]) + .disable(["strikethrough"]) + .use(mitTexMath, { + engine: require("katex"), + delimiters: "gitlab", + katexOptions: { macros: { "\\RR": "\\mathbb{R}" } }, + }) + .use(mitMulMd); +const app = express(); + +app.use(express.static("./")); +app.use(express.static(path.join(__dirname, "css"))); +app.set("views", "./views"); +app.set("view engine", "ejs"); +app.engine("ejs", require("ejs").__express); + +app.get("/", (req, res) => { + let readStream = fs.createReadStream("./mds/cstruct2luatable.md", "utf-8"); + // FIXME-this is gonna be so wrong when the md is bigger than one chunk + readStream.on("data", (chunk) => { + res.render("index", { + data: { + blogHttp: mit.render(chunk), + mds: ["c struct to lua table", "lazy makefiles", "telegram lua"], + }, + }); + }); +}); + +app.listen(3000); diff --git a/views/index.ejs b/views/index.ejs new file mode 100644 index 0000000..f1f7bb1 --- /dev/null +++ b/views/index.ejs @@ -0,0 +1,18 @@ + + + + + + Blog + + + +
+ <% data.mds.forEach(function(md) { %> +

<%= md %>

+ <%= md %> + <% }) %> +
+ <%- data.blogHttp %> + + -- cgit v1.2.3