Files are enriched in ssg5 as they are parsed instead of doing it in 2 steps

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2022-01-24 21:47:32 +01:00
parent b112eae79f
commit 3bcd9c4e00
No known key found for this signature in database
GPG Key ID: 0C87282F76E61283
3 changed files with 10 additions and 12 deletions

View File

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

View File

@ -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 ($) {
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("./dst/" + file, $);
});
fsc.writeFile(file, $);
});

1
ssg5
View File

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