all repos — archive/homestead @ e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f

My future indieweb platform

feat: Add code block highlighting Theme is configurable

Alan Pearce
commit

e7b08b1dfe3f2a2596deb6e2a72bb79805d3708f

parent

a67e38d1a82c95db5bd24183e81b31438f60dd2c

1 file changed, 22 insertions(+), 0 deletions(-)

changed files
M src/actions.jssrc/actions.js
@@ -1,5 +1,7 @@
"use strict"; +const fs = require("fs"); +const path = require("path"); const send = require("koa-send"); const responders = require("./responders");
@@ -7,6 +9,25 @@ function home(config, posts) {
const postsArray = Array.from(posts.values()); return async function(ctx, next) { responders.home(ctx, config, postsArray); + }; +} + +function highlightTheme(config) { + const theme = config.posts.code.theme; + const themeFile = path.resolve( + __dirname, + `../node_modules/highlight.js/styles/${theme}.css` + ); + + if (!fs.existsSync(themeFile)) { + throw new Error(`Couldn't find highlight theme ${theme}`); + } + + const css = fs.readFileSync(themeFile, "utf-8"); + + return async function(ctx, next) { + ctx.type = "css"; + ctx.body = css; }; }
@@ -41,6 +62,7 @@ }
module.exports = { home, + highlightTheme, post, taxonGenerator, serveFiles