From c316f3c0f6008f84c7d59dccebe906f5e66346df Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@hoyer.xyz>
Date: Fri, 22 Mar 2024 09:29:29 +0100
Subject: [PATCH 1/3] remove custom theme modification repo

Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
---
 .gitmodules    | 4 ----
 themes/abridge | 1 -
 2 files changed, 5 deletions(-)
 delete mode 160000 themes/abridge

diff --git a/.gitmodules b/.gitmodules
index ea666c0..e69de29 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +0,0 @@
-[submodule "themes/abridge"]
-path = themes/abridge
-url = https://git.hoyer.xyz/harald/abridge.git
-
diff --git a/themes/abridge b/themes/abridge
deleted file mode 160000
index 21dfeb9..0000000
--- a/themes/abridge
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 21dfeb963068be3467b572a3307dd11c9efc33ba

From 03c1097fa3d6c535edd32da5d7471b2c8336375e Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@hoyer.xyz>
Date: Fri, 22 Mar 2024 09:32:03 +0100
Subject: [PATCH 2/3] add original themes/abridge

Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
---
 .gitmodules    | 3 +++
 themes/abridge | 1 +
 2 files changed, 4 insertions(+)
 create mode 160000 themes/abridge

diff --git a/.gitmodules b/.gitmodules
index e69de29..a7c4720 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "abridge-orig"]
+	path = themes/abridge
+	url = https://github.com/Jieiku/abridge.git
diff --git a/themes/abridge b/themes/abridge
new file mode 160000
index 0000000..d45bc26
--- /dev/null
+++ b/themes/abridge
@@ -0,0 +1 @@
+Subproject commit d45bc26c2250f573a0d83f755831857999fc125f

From ee2611a5d768862a537ea6816ac87d36dfc0c817 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@hoyer.xyz>
Date: Fri, 22 Mar 2024 09:36:26 +0100
Subject: [PATCH 3/3] abridge update

Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
---
 package_abridge.js | 128 +++++++++++++++++++++++++--------------------
 1 file changed, 71 insertions(+), 57 deletions(-)

diff --git a/package_abridge.js b/package_abridge.js
index 52c704e..cd9d331 100644
--- a/package_abridge.js
+++ b/package_abridge.js
@@ -8,6 +8,9 @@ const util  = require("util");
 const { exec } = require("child_process");
 const execPromise = util.promisify(exec);
 
+if (!(fs.existsSync('config.toml'))) {
+  throw new Error('ERROR: cannot find config.toml!');
+}
 const tomlString = String(fs.readFileSync('config.toml'));
 const data = TOML.parse(tomlString);
 const js_prestyle = data.extra.js_prestyle;
@@ -37,17 +40,23 @@ async function execWrapper(cmd) {
     console.log(stdout);
   }
   if (stderr) {
-    console.log('Error: '+stderr);
+    console.log('ERROR: '+stderr);
   }
 }
 
 async function abridge() {
   if (offline === false) {
-    replace.sync({files: 'config.toml', from: /base_url.*=.*/g, to: "base_url = \""+online_url+"\""});
-    replace.sync({files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \""+online_indexformat+"\""});
+    if (typeof online_url !== 'undefined' && typeof online_indexformat !== 'undefined') {
+      replace.sync({files: 'config.toml', from: /base_url.*=.*/g, to: "base_url = \""+online_url+"\""});
+      replace.sync({files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \""+online_indexformat+"\""});
+    }
   } else if (offline === true) {
-    replace.sync({files: 'config.toml', from: /base_url.*=.*/g, to: "base_url = \""+__dirname+"\/public\""});
-    replace.sync({files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_javascript\""});
+    if (typeof online_url !== 'undefined' && typeof online_indexformat !== 'undefined') {
+      replace.sync({files: 'config.toml', from: /base_url.*=.*/g, to: "base_url = \""+__dirname+"\/public\""});
+      replace.sync({files: 'config.toml', from: /index_format.*=.*/g, to: "index_format = \"elasticlunr_javascript\""});
+    } else {
+      throw new Error('ERROR: offline = true requires that online_url and online_indexformat are set in config.toml, so that the base_url and index_format can be restored if offline is later set to false.');
+    }
   }
 
   console.log('Zola Build to generate files for minification:');
@@ -105,64 +114,69 @@ async function abridge() {
   }
 
   if (pwa) {// Update pwa settings, file list, and hashes.
-    // update from abridge theme.
-    fs.copyFileSync(bpath+'static/sw.js', 'static/sw.js');
-    fs.copyFileSync(bpath+'static/js/sw_load.js', 'static/js/sw_load.js');
-    // Update settings in PWA javascript file, using options parsed from config.toml.  sw.min.js?v=3.10.0",  "++"
-    if (fs.existsSync('static/js/sw_load.js')) {
-      sw_load_min = '.js?v=';
-      if (js_bundle) {
-        sw_load_min = '.min.js?v=';
+    if (typeof pwa_VER !== 'undefined' && typeof pwa_NORM_TTL !== 'undefined' && typeof pwa_LONG_TTL !== 'undefined' && typeof pwa_TTL_NORM !== 'undefined' && typeof pwa_TTL_LONG !== 'undefined' && typeof pwa_TTL_EXEMPT !== 'undefined') {
+      // update from abridge theme.
+      fs.copyFileSync(bpath+'static/sw.js', 'static/sw.js');
+      fs.copyFileSync(bpath+'static/js/sw_load.js', 'static/js/sw_load.js');
+      // Update settings in PWA javascript file, using options parsed from config.toml.  sw.min.js?v=3.10.0",  "++"
+      if (fs.existsSync('static/js/sw_load.js')) {
+        sw_load_min = '.js?v=';
+        if (js_bundle) {
+          sw_load_min = '.min.js?v=';
+        }
+        replace.sync({files: 'static/js/sw_load.js', from: /sw.*v=.*/g, to: "sw"+sw_load_min+pwa_VER+"\","});
       }
-      replace.sync({files: 'static/js/sw_load.js', from: /sw.*v=.*/g, to: "sw"+sw_load_min+pwa_VER+"\","});
-    }
-    if (fs.existsSync('static/sw.js')) {
-      replace.sync({files: 'static/sw.js', from: /NORM_TTL.*=.*/g, to: "NORM_TTL = "+pwa_NORM_TTL+";"});
-      replace.sync({files: 'static/sw.js', from: /LONG_TTL.*=.*/g, to: "LONG_TTL = "+pwa_LONG_TTL+";"});
-      replace.sync({files: 'static/sw.js', from: /TTL_NORM.*=.*/g, to: "TTL_NORM = ["+pwa_TTL_NORM+"];"});
-      replace.sync({files: 'static/sw.js', from: /TTL_LONG.*=.*/g, to: "TTL_LONG = ["+pwa_TTL_LONG+"];"});
-      replace.sync({files: 'static/sw.js', from: /TTL_EXEMPT.*=.*/g, to: "TTL_EXEMPT = ["+pwa_TTL_EXEMPT+"];"});
-    }
-
-    if (pwa_cache_all) {
-      // Generate array from the list of files, for the entire site.
-
-      var dir = 'public';
-      try {
-        fs.mkdirSync(dir);
-      } catch(e) {
-        if (e.code != 'EEXIST') throw e;
+      if (fs.existsSync('static/sw.js')) {
+        replace.sync({files: 'static/sw.js', from: /NORM_TTL.*=.*/g, to: "NORM_TTL = "+pwa_NORM_TTL+";"});
+        replace.sync({files: 'static/sw.js', from: /LONG_TTL.*=.*/g, to: "LONG_TTL = "+pwa_LONG_TTL+";"});
+        replace.sync({files: 'static/sw.js', from: /TTL_NORM.*=.*/g, to: "TTL_NORM = ["+pwa_TTL_NORM+"];"});
+        replace.sync({files: 'static/sw.js', from: /TTL_LONG.*=.*/g, to: "TTL_LONG = ["+pwa_TTL_LONG+"];"});
+        replace.sync({files: 'static/sw.js', from: /TTL_EXEMPT.*=.*/g, to: "TTL_EXEMPT = ["+pwa_TTL_EXEMPT+"];"});
       }
-      const path = './public/';
-      cache = 'this.BASE_CACHE_FILES = [';
-      files = fs.readdirSync(path, { recursive: true, withFileTypes: false })
-      .forEach(
-        (file) => {
-          // check if is directory, if not then add the path/file
-          if (!fs.lstatSync(path+file).isDirectory()) {
-            // format output
-            item = "/"+file.replace(/index\.html$/i,'');// strip index.html from path
-            item = item.replace(/^\/sw(\.min)?\.js/i,'');// dont cache service worker
 
-            // if formatted output is not empty line then append it to cache var
-            if (item != '') {// skip empty lines
-              cache = cache+"'"+item+"',";
+      if (pwa_cache_all === true) {
+        console.log('info: pwa_cache_all = true in config.toml, so caching the entire site.\n');
+        // Generate array from the list of files, for the entire site.
+
+        var dir = 'public';
+        try {
+          fs.mkdirSync(dir);
+        } catch(e) {
+          if (e.code != 'EEXIST') throw e;
+        }
+        const path = './public/';
+        cache = 'this.BASE_CACHE_FILES = [';
+        files = fs.readdirSync(path, { recursive: true, withFileTypes: false })
+        .forEach(
+          (file) => {
+            // check if is directory, if not then add the path/file
+            if (!fs.lstatSync(path+file).isDirectory()) {
+              // format output
+              item = "/"+file.replace(/index\.html$/i,'');// strip index.html from path
+              item = item.replace(/^\/sw(\.min)?\.js/i,'');// dont cache service worker
+
+              // if formatted output is not empty line then append it to cache var
+              if (item != '') {// skip empty lines
+                cache = cache+"'"+item+"',";
+              }
             }
           }
-        }
-      );
-      cache = cache.slice(0, -1)+'];'// remove the last comma and close the array
-    } else if (pwa_BASE_CACHE_FILES) {
-      cache = 'this.BASE_CACHE_FILES = ['+pwa_BASE_CACHE_FILES+'];';
-    }
+        );
+        cache = cache.slice(0, -1)+'];'// remove the last comma and close the array
+      } else if (pwa_BASE_CACHE_FILES) {
+        cache = 'this.BASE_CACHE_FILES = ['+pwa_BASE_CACHE_FILES+'];';
+      }
 
-    // update the BASE_CACHE_FILES variable in the sw.js service worker file
-    results = replace.sync({
-      files: 'static/sw.js',
-      from: /this\.BASE_CACHE_FILES =.*/g,
-      to: cache,
-      countMatches: true,
-    });
+      // update the BASE_CACHE_FILES variable in the sw.js service worker file
+      results = replace.sync({
+        files: 'static/sw.js',
+        from: /this\.BASE_CACHE_FILES =.*/g,
+        to: cache,
+        countMatches: true,
+      });
+    } else {
+      throw new Error('ERROR: pwa requires that pwa_VER, pwa_NORM_TTL, pwa_LONG_TTL, pwa_TTL_NORM, pwa_TTL_LONG, pwa_TTL_EXEMPT are set in config.toml.');
+    }
   }
 
   if (bpath === '') {// abridge used directly