From c2d72e09747a2a4abe9602e1ba49a1b4649c9d3c Mon Sep 17 00:00:00 2001 From: Jieiku Date: Fri, 14 Aug 2026 15:10:15 -0700 Subject: Update for Zola 0.23.3 --- package_abridge.js | 77 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 24 deletions(-) (limited to 'package_abridge.js') diff --git a/package_abridge.js b/package_abridge.js index e82eee8..7c7a893 100644 --- a/package_abridge.js +++ b/package_abridge.js @@ -8,10 +8,10 @@ const { exec } = require("child_process"); const { exit } = require('process'); const execPromise = util.promisify(exec); -if (!(fs.existsSync('config.toml'))) { - throw new Error('ERROR: cannot find config.toml!'); +if (!(fs.existsSync('zola.toml'))) { + throw new Error('ERROR: cannot find zola.toml!'); } -const tomlString = String(fs.readFileSync('config.toml')); +const tomlString = String(fs.readFileSync('zola.toml')); const data = TOML.parse(tomlString); const js_prestyle = data.extra.js_prestyle; const js_switcher = data.extra.js_switcher; @@ -54,7 +54,7 @@ async function execWrapper(cmd) { console.log(stdout); } if (stderr) { - console.log('ERROR: ' + stderr); + console.log(stderr); } } @@ -63,16 +63,16 @@ async function abridge() { const { replaceInFileSync } = await import('replace-in-file'); // set index_format for chosen search_library accordingly. if (search_library === 'offline') { - replaceInFileSync({ files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_javascript\"" }); + replaceInFileSync({ files: 'zola.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_javascript\"" }); args = args + " -u \"" + __dirname + "\/public\""//set base_url to the path on disk for offline site. } else if (search_library === 'elasticlunrjava') { - replaceInFileSync({ files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_javascript\"" }); + replaceInFileSync({ files: 'zola.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_javascript\"" }); } else if (search_library === 'elasticlunr') { - replaceInFileSync({ files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_json\"" }); + replaceInFileSync({ files: 'zola.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_json\"" }); } else if (search_library === 'pagefind') { - replaceInFileSync({ files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \"fuse_json\"" }); + replaceInFileSync({ files: 'zola.toml', from: /index_format.*=.*/g, to: "index_format = \"fuse_json\"" }); } else if (search_library === 'tinysearch') { - replaceInFileSync({ files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \"fuse_json\"" }); + replaceInFileSync({ files: 'zola.toml', from: /index_format.*=.*/g, to: "index_format = \"fuse_json\"" }); } console.log('Zola Build to generate files for minification:'); @@ -104,11 +104,36 @@ async function abridge() { var hash = Math.floor(new Date().getTime() / 1000); fs.renameSync(path.join(__dirname, "static/js/pagefind-entry.json"), path.join(__dirname, "static/js/pagefind-entry-" + hash + ".json")); - // original: var e=await(await fetch(this.basePath+"pagefind-entry.json?ts="+Date.now())).json(); - // new: var e=await(await fetch(this.basePath+"pagefind-entry-1723268715.json")).json(); - // Tricky regex, so I split it into two replaceInFileSync() calls, pull requests welcome if you can improve this. - replaceInFileSync({ files: path.join(__dirname, "static/js/pagefind_search.js"), from: /pagefind-entry\.json\?ts=/g, to: "pagefind-entry-" + hash + "\.json" }); - replaceInFileSync({ files: path.join(__dirname, "static/js/pagefind_search.js"), from: /Date.now\(\)/g, to: "\"\"" }); + // Pagefind builds the entry URL in several forms across versions, e.g.: + // this.basePath+"pagefind-entry.json?ts="+Date.now() + // `${this.basePath}pagefind-entry.json?ts=${Date.now()}` + // Replace those with a build-time hashed filename (no cache-bust query). + // Also strip import.meta (ESM-only) so the classic