aboutsummaryrefslogtreecommitdiff
path: root/package_abridge.js
diff options
context:
space:
mode:
authorJieiku2024-08-07 13:39:36 -0700
committerJieiku2024-08-07 13:39:36 -0700
commitdcfd66a2f8ef4d1777deaaabed94d90c9e247dc8 (patch)
tree21c4f4fa849cb10df857a69e7f83320a43a80554 /package_abridge.js
parent0b5c5a47ff524cc3a949b7b4d29efdf7cc74d0eb (diff)
downloadabridge-dcfd66a2f8ef4d1777deaaabed94d90c9e247dc8.tar.gz
abridge-dcfd66a2f8ef4d1777deaaabed94d90c9e247dc8.tar.bz2
abridge-dcfd66a2f8ef4d1777deaaabed94d90c9e247dc8.zip
node script optimizations
Diffstat (limited to 'package_abridge.js')
-rw-r--r--package_abridge.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/package_abridge.js b/package_abridge.js
index 7c673f1..1edc243 100644
--- a/package_abridge.js
+++ b/package_abridge.js
@@ -139,7 +139,7 @@ async function abridge() {
if (e.code != 'EEXIST') throw e;
}
const path = './public/';
- cache = 'this.BASE_CACHE_FILES = [';
+ cache = '';
files = fs.readdirSync(path, { recursive: true, withFileTypes: false })
.forEach(
(file) => {
@@ -149,6 +149,7 @@ async function abridge() {
item = "/"+file.replace(/index\.html$/i,'');// strip index.html from path
item = item.replace(/\\/g,'/');// replace backslash with forward slash for Windows
item = item.replace(/^\/sw(\.min)?\.js/i,'');// dont cache service worker
+ item = item.replace(/^\/_headers/i,'');// dont cache the cloudflare _headers file
// if formatted output is not empty line then append it to cache var
if (item != '') {// skip empty lines
@@ -157,11 +158,13 @@ async function abridge() {
}
}
);
- cache = cache.slice(0, -1)+'];'// remove the last comma and close the array
+ cache = cache.slice(0, -1)// remove the last comma
} else if (pwa_BASE_CACHE_FILES) {
- cache = 'this.BASE_CACHE_FILES = ['+pwa_BASE_CACHE_FILES+'];';
+ cache = pwa_BASE_CACHE_FILES;
}
+ cache = cache.split(",").sort().join(",")//sort the cache list, this should help keep the commit history cleaner.
+ cache = 'this.BASE_CACHE_FILES = ['+cache+'];';
// update the BASE_CACHE_FILES variable in the sw.js service worker file
results = replaceInFileSync({
files: 'static/sw.js',
@@ -212,11 +215,6 @@ async function abridge() {
await execWrapper('zola build'+args);
}
-async function searchChange(searchOption) {
- const { replaceInFileSync } = await import('replace-in-file');
- replaceInFileSync({files: 'config.toml', from: /search_library.*=.*/g, to: 'search_library = \"'+searchOption+'\"'});
-}
-
function bundle(bpath,js_prestyle,js_switcher,js_email_encode,js_copycode,search_library,index_format,uglyurls,pwa) {
minify_files = [];
@@ -288,6 +286,11 @@ function minify(fileA,outfile) {
}
+async function searchChange(searchOption) {
+ const { replaceInFileSync } = await import('replace-in-file');
+ replaceInFileSync({files: 'config.toml', from: /search_library.*=.*/g, to: 'search_library = \"'+searchOption+'\"'});
+}
+
if (args === ' offline') {
searchChange('offline');
} else if (args === ' elasticlunrjava') {