All HTML files will be enriched once generated
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
04804caf3e
commit
bc2a00556a
11
Dockerfile
11
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
|
||||
|
||||
|
22
enrich_codeblocks.js
Normal file
22
enrich_codeblocks.js
Normal 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
7
package.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"fs-cheerio": "^3.0.0",
|
||||
"prismjs": "^1.26.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user