All HTML files will be enriched once generated

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2022-01-24 19:07:20 +01:00
parent 04804caf3e
commit bc2a00556a
No known key found for this signature in database
GPG Key ID: 0C87282F76E61283
3 changed files with 35 additions and 5 deletions

View File

@ -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

22
enrich_codeblocks.js Normal file
View File

@ -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, $);
});
});

7
package.json Normal file
View File

@ -0,0 +1,7 @@
{
"dependencies": {
"cheerio": "^1.0.0-rc.10",
"fs-cheerio": "^3.0.0",
"prismjs": "^1.26.0"
}
}