From 3bcd9c4e00b02b67fec7497e8023c126809e95d0 Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Mon, 24 Jan 2022 21:47:32 +0100 Subject: [PATCH] Files are enriched in ssg5 as they are parsed instead of doing it in 2 steps Signed-off-by: Louis Vallat --- Dockerfile | 3 +-- enrich_codeblocks.js | 18 ++++++++---------- ssg5 | 1 + 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8af0d83..e5ea9b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,7 @@ RUN apk --no-cache add gcc git make musl-dev npm && \ cd lowdown && ./configure && make && make regress && make install && cd .. && \ 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 + ./ssg5 ./src/ ./dst/ "Le blog de Louis Vallat" "https://blog.louis-vallat.xyz" && rm dst/.files FROM nginx diff --git a/enrich_codeblocks.js b/enrich_codeblocks.js index ceed1b6..11fda5a 100644 --- a/enrich_codeblocks.js +++ b/enrich_codeblocks.js @@ -8,15 +8,13 @@ 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, $); +const file = process.argv[2]; +fsc.readFile(file).then(function ($, err) { + $('*[class^="language-"]').replaceWith(function () { + return $(this).html(Prism.highlight( + $(this).text(), + Prism.languages[$(this).attr('class').split('-')[1]]) + ); }); + fsc.writeFile(file, $); }); diff --git a/ssg5 b/ssg5 index b5a2d4f..ddadbda 100755 --- a/ssg5 +++ b/ssg5 @@ -194,6 +194,7 @@ render_md_files_lowdown() { --html-no-skiphtml \ --html-no-escapehtml < "$1/$f" | render_html_file "$3" "$(head -n 3 ${1}/${f} | tail -n 1)" > "$2/${f%\.md}.html" + node ./enrich_codeblocks.js "$2/${f%\.md}.html" done }