diff --git a/Dockerfile b/Dockerfile index f0c9b8d..8af0d83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,14 +2,15 @@ FROM alpine AS builder WORKDIR /root -COPY src ./src -COPY ssg5 . +COPY . . -RUN apk --no-cache add gcc git make musl-dev && \ +RUN apk --no-cache add gcc git make musl-dev npm && \ git clone -b VERSION_0_10_0 https://github.com/kristapsdz/lowdown.git && \ cd lowdown && ./configure && make && make regress && make install && cd .. && \ - chmod u+x ./ssg5 && mkdir dst && \ - ./ssg5 ./src/ ./dst/ "Le blog de Louis Vallat" "https://blog.louis-vallat.xyz" && rm dst/.files + npm install && \ + chmod u+x ./ssg5 && mkdir -p dst && \ + ./ssg5 ./src/ ./dst/ "Le blog de Louis Vallat" "https://blog.louis-vallat.xyz" && rm dst/.files && \ + node ./enrich_codeblocks.js FROM nginx diff --git a/enrich_codeblocks.js b/enrich_codeblocks.js new file mode 100644 index 0000000..ceed1b6 --- /dev/null +++ b/enrich_codeblocks.js @@ -0,0 +1,22 @@ +const Prism = require('prismjs'); +const fs = require('fs'); +const cheerio = require('cheerio'); +const loadLanguages = require('prismjs/components/'); +const fsc = require('fs-cheerio'); + +loadLanguages([ + 'rust', 'py', 'cpp', 'c', 'git' +]); + +fs.readdirSync("./dst/").filter(e => e.endsWith(".html")).forEach(file => { + console.log("Enriching " + file) + fsc.readFile("./dst/" + file).then(function ($) { + $('*[class^="language-"]').replaceWith(function () { + return $(this).html(Prism.highlight( + $(this).text(), + Prism.languages[$(this).attr('class').split('-')[1]]) + ); + }); + fsc.writeFile("./dst/" + file, $); + }); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..96ef342 --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "cheerio": "^1.0.0-rc.10", + "fs-cheerio": "^3.0.0", + "prismjs": "^1.26.0" + } +}