Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jieiku committed Oct 6, 2024
1 parent cd29bda commit 086f54c
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 42 deletions.
4 changes: 2 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ taxonomies = [

[search] # Options specific to elasticlunr search.
# index format can be: elasticlunr_json or elasticlunr_javascript or fuse_json
index_format = "fuse_json"
index_format = "elasticlunr_json"
include_title = true # include title of page/section in index
include_description = true # include description of page/section in index
include_content = true # include rendered content of page/section in index
Expand Down Expand Up @@ -221,7 +221,7 @@ js_prestyle = true # used to preload: FontAwesome, Katex, external Google Fonts
js_switcher = true # The button that allows manually changing between light/dark mode.
js_switcher_default = "dark" # default nojs switcher mode: dark, light (make sure to also set $switcherDefault in abridge.scss)

search_library = "pagefind"
search_library = "elasticlunr"
stylesheets = ["abridge.css"]

webmanifest = "manifest.min.json" # Required for PWAs
Expand Down
55 changes: 23 additions & 32 deletions package_abridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ if (fs.existsSync('./themes')) {
bpath = 'themes/abridge/';
}
// cleanup pagefind files from old builds.
_rmRegex(path.join(bpath, "static/js/"), /^wasm.*pagefind$/);
_rmRegex(path.join(bpath, "static/js/"), /^pagefind.*pf_meta$/);
_rmRegex(path.join(bpath, "static/js/"), /^pagefind-entry.*json$/);
_rmRecursive(path.join(bpath, "static/js/index"));
_rmRecursive(path.join(bpath, "static/js/fragment"));
_rmRegex(path.join(__dirname, "static/js/"), /^wasm.*pagefind$/);
_rmRegex(path.join(__dirname, "static/js/"), /^pagefind.*pf_meta$/);
_rmRegex(path.join(__dirname, "static/js/"), /^pagefind-entry.*json$/);
_rmRecursive(path.join(__dirname, "static/js/index"));
_rmRecursive(path.join(__dirname, "static/js/fragment"));

async function execWrapper(cmd) {
const { stdout, stderr } = await execPromise(cmd);
Expand Down Expand Up @@ -93,9 +93,9 @@ async function abridge() {
if (search_library === 'pagefind') {
// Generate pagefind index at start, otherwise it happens too late asyncronously.
await createPagefindIndex(); // makes program wait for pagefind build execution
_rmRegex(path.join(bpath, "static/js/"), /^pagefind\.js$/);//pagefind temporary intermediate files
_rmRegex(path.join(bpath, "static/js/"), /^pagefind-.*\.js$/);//pagefind temporary intermediate files
_rmRegex(path.join(bpath, "static/js/"), /^pagefind-.*\.css$/);//pagefind temporary intermediate files
_rmRegex(path.join(__dirname, "static/js/"), /^pagefind\.js$/);//pagefind temporary intermediate files
_rmRegex(path.join(__dirname, "static/js/"), /^pagefind-.*\.js$/);//pagefind temporary intermediate files
_rmRegex(path.join(__dirname, "static/js/"), /^pagefind-.*\.css$/);//pagefind temporary intermediate files

// This line in pagefind is causing a problem for the PWA:
// var e = await (await fetch(this.basePath + "pagefind-entry.json?ts=" + Date.now())).json();
Expand Down Expand Up @@ -224,7 +224,7 @@ async function abridge() {
minify(abridge_bundle, 'static/js/abridge.min.js');

// cleanup
_rmRegex(path.join(bpath, "static/js/"), /^pagefind_search\.js$/);//pagefind intermediate file that is now in bundle.
_rmRegex(path.join(__dirname, "static/js/"), /^pagefind_search\.js$/);//pagefind intermediate file that is now in bundle.

console.log('Zola Build to generate new integrity hashes for the previously minified files:');
await execWrapper('zola build' + args);
Expand Down Expand Up @@ -284,33 +284,33 @@ function bundle(bpath, js_prestyle, js_switcher, js_email_encode, js_copycode, s
minify_files = [];

if (js_prestyle) {
minify_files.push(bpath + 'static/js/prestyle.js');
minify_files.push(path.join(bpath, 'static/js/prestyle.js'));
}
if (js_switcher) {
minify_files.push(bpath + 'static/js/theme_button.js');
minify_files.push(path.join(bpath, 'static/js/theme_button.js'));
}
if (js_email_encode) {
minify_files.push(bpath + 'static/js/email.js');
minify_files.push(path.join(bpath, 'static/js/email.js'));
}
if (js_copycode) {
minify_files.push(bpath + 'static/js/codecopy.js');
minify_files.push(path.join(bpath, 'static/js/codecopy.js'));
}
if (search_library) {
if ((search_library === 'offline' || (search_library === 'elasticlunrjava' && uglyurls === true))) {
minify_files.push('public/search_index.en.js');
minify_files.push(bpath + 'static/js/elasticlunr.min.js');
minify_files.push(bpath + 'static/js/searchjavaugly.js');
minify_files.push(path.join(bpath, 'static/js/elasticlunr.min.js'));
minify_files.push(path.join(bpath, 'static/js/searchjavaugly.js'));
} else if (search_library === 'elasticlunrjava') {
minify_files.push('public/search_index.en.js');
minify_files.push(bpath + 'static/js/elasticlunr.min.js');
minify_files.push(bpath + 'static/js/searchjava.js');
minify_files.push(path.join(bpath, 'static/js/elasticlunr.min.js'));
minify_files.push(path.join(bpath, 'static/js/searchjava.js'));
} else if (search_library === 'elasticlunr') {//abridge default
minify_files.push(bpath + 'static/js/elasticlunr.min.js');
minify_files.push(bpath + 'static/js/search.js');
minify_files.push(path.join(bpath, 'static/js/elasticlunr.min.js'));
minify_files.push(path.join(bpath, 'static/js/search.js'));
} else if (search_library === 'pagefind') {
minify_files.push(path.join(__dirname, 'static/js/pagefind_search.js'));
} else if (search_library === 'tinysearch') {
minify_files.push(bpath + 'static/js/tinysearch.js');
minify_files.push(path.join(bpath, 'static/js/tinysearch.js'));
}
}
if (pwa) {
Expand Down Expand Up @@ -487,16 +487,10 @@ async function sync() {

// Check for changes in package.json
const packageJson = path.join(__dirname, "package.json");
const submodulePackageJson = path.join(
__dirname,
"themes/abridge/package.json"
);
const submodulePackageJson = path.join(__dirname, "themes/abridge/package.json");

const packageJsonContent = fs.readFileSync(packageJson, "utf-8");
const submodulePackageJsonContent = fs.readFileSync(
submodulePackageJson,
"utf-8"
);
const submodulePackageJsonContent = fs.readFileSync(submodulePackageJson, "utf-8");

// Check for changes in dependencies - prompting an npm update
let checkPackageVersion = function (content) {
Expand Down Expand Up @@ -524,10 +518,7 @@ async function sync() {
}

const configToml = path.join(__dirname, "config.toml");
const submoduleConfigToml = path.join(
__dirname,
"themes/abridge/config.toml"
);
const submoduleConfigToml = path.join(__dirname, "themes/abridge/config.toml");

let adjustTomlContent = function (content) {
content = content.replace(/^\s+|\s+$|\s+(?=\s)/g, ""); // Remove all leading and trailing whitespaces and multiple whitespaces
Expand Down
2 changes: 1 addition & 1 deletion static/_headers
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Referrer-Policy: strict-origin-when-cross-origin
Strict-Transport-Security: max-age=63072000; includeSubdomains
Permissions-Policy: interest-cohort=(), accelerometer=(), ambient-light-sensor=(), battery=(), bluetooth=(), browsing-topics=(), camera=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), gamepad=(), geolocation=(), gyroscope=(), hid=(), identity-credentials-get=(), idle-detection=(), magnetometer=(), microphone=(), midi=(), otp-credentials=(), payment=(), picture-in-picture=(), publickey-credentials-create=(), publickey-credentials-get=(), serial=(), storage-access=(), sync-xhr=(), usb=(), web-share=(), window-management=(), xr-spatial-tracking=()
Content-Security-Policy: default-src 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; manifest-src 'self'; worker-src 'self'; form-action 'self'; connect-src 'self' *.hyvor.com ws://*.hyvor.com; script-src 'wasm-unsafe-eval' 'self' talk.hyvor.com; img-src 'self' data: talk.hyvor.com cdn.cloudflare.com; frame-src 'self' www.youtube-nocookie.com player.vimeo.com streamable.com www.streamable.com; media-src 'self' data: cdn.cloudflare.com www.youtube-nocookie.com player.vimeo.com; font-src 'self' cdn.cloudflare.com cdn.jsdelivr.net fonts.gstatic.com; style-src 'self' talk.hyvor.com cdn.cloudflare.com cdn.jsdelivr.net fonts.googleapis.com;
Content-Security-Policy: default-src 'none'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; manifest-src 'self'; worker-src 'self'; form-action 'self'; connect-src 'self' *.hyvor.com ws://*.hyvor.com; script-src 'self' talk.hyvor.com; img-src 'self' data: talk.hyvor.com cdn.cloudflare.com; frame-src 'self' www.youtube-nocookie.com player.vimeo.com streamable.com www.streamable.com; media-src 'self' data: cdn.cloudflare.com www.youtube-nocookie.com player.vimeo.com; font-src 'self' cdn.cloudflare.com cdn.jsdelivr.net fonts.gstatic.com; style-src 'self' talk.hyvor.com cdn.cloudflare.com cdn.jsdelivr.net fonts.googleapis.com;

/*.js
Cache-Control: public, max-age=604800, must-revalidate
Expand Down
Loading

0 comments on commit 086f54c

Please sign in to comment.