Skip to content

Commit

Permalink
Add pagefind search to abridge (#179)
Browse files Browse the repository at this point in the history
* Start process of adding pagefind to abridge

* Write to static to make index appear in public

* Add multilingual support

* Minify files and fix running in script

* Add pagefind files

* Add loading of pagefind data

* Update gitignore to remove pagefind index files

* Get basic search result surfacing working

* Remove duplicate entries in search results

* Sanitise except to remove unnecessary details

* Finalise addition of pagefind

* Add missing await

* Fix config.toml and remove old files on rebuild

* Finish chores on pagefind addition
  • Loading branch information
Hysterelius authored Jul 20, 2024
1 parent 4dab5b9 commit a7244a2
Show file tree
Hide file tree
Showing 24 changed files with 1,778 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ static/tinysearch_engine.js
static/tinysearch_engine.d.ts
static/tinysearch_engine_bg.wasm.d.ts
static/package.json
static/js/pagefind.*.pf_meta
static/js/index
static/js/fragment
4 changes: 2 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ taxonomies = [
#hard_link_static = false # set to true to hard link instead of copying, useful for very large files.

[search] # Options specific to elasticlunr search.
# index format can be: elasticlunr_json or elasticlunr_javascript
# index format can be: elasticlunr_json or elasticlunr_javascript or 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
Expand Down Expand Up @@ -212,7 +212,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 = 'elasticlunr'
search_library = "elasticlunr"
stylesheets = ["abridge.css"]

webmanifest = "manifest.min.json" # Required for PWAs
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
"license": "MIT",
"homepage": "https://github.com/Jieiku/abridge",
"scripts": {
"abridge": "node -e \"if ( require('fs').existsSync('./themes/abridge/package_abridge.js')) {require('fs').copyFileSync('./themes/abridge/package_abridge.js', './package_abridge.js')}\" && node package_abridge.js"
"abridge": "node -e \"if ( require('fs').existsSync('./themes/abridge/package_abridge.js')) {require('fs').copyFileSync('./themes/abridge/package_abridge.js', './package_abridge.js')}\" && node package_abridge.js",
"search:pagefind": "node -e \"if ( require('fs').existsSync('./themes/abridge/static/js/searchChange.js')) {require('fs').copyFileSync('./themes/abridge/static/js/searchChange.js', './static/js/searchChange.js')}\" && node ./static/js/searchChange.js --pagefind",
"search:elasticlunr": "node -e \"if ( require('fs').existsSync('./themes/abridge/static/js/searchChange.js')) {require('fs').copyFileSync('./themes/abridge/static/js/searchChange.js', './static/js/searchChange.js')}\" && node ./static/js/searchChange.js --elasticlunr"
},
"dependencies": {
"fast-toml": "^0.5.4",
"uglify-js": "^3.17.4",
"jsonminify": "^0.4.2",
"replace-in-file": "^7.0.1"
"pagefind": "^1.1.0",
"replace-in-file": "^7.0.1",
"uglify-js": "^3.17.4"
}
}
17 changes: 16 additions & 1 deletion package_abridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ async function abridge() {
replace.sync({files: 'content/static/tinysearch_json.md', from: /draft.*=.*/g, to: "draft = true"});
}
// zola build && stork build --input public/data_stork/index.html --output static/stork.st
} else if (search_library === 'pagefind') {
if (fs.existsSync('content/static/stork_toml.md')) {
replace.sync({files: 'content/static/stork_toml.md', from: /draft.*=.*/g, to: "draft = true"});
}
if (fs.existsSync('content/static/tinysearch_json.md')) {
replace.sync({files: 'content/static/tinysearch_json.md', from: /draft.*=.*/g, to: "draft = true"});
}

// Run the pagefind script to generate the index files.
// Has to happen at start otherwise, it happens too late asyncronously.
const createIndex = require('./static/js/pagefind.index.js'); // run the pagefind index.js script
await createIndex(); // makes program wait for pagefind build execution
}

if (pwa) {// Update pwa settings, file list, and hashes.
Expand Down Expand Up @@ -185,7 +197,7 @@ async function abridge() {
}

if (bpath === '') {// abridge used directly
// These are truely static js files, so they should only need to be updated by abridge maintainer or contributors.
// These are truely static js files, so they should only need to be updated by the abridge maintainer or contributors.
minify(['static/js/theme.js']);
minify(['static/js/theme_light.js']);
minify(['static/js/katex.min.js','static/js/mathtex-script-type.min.js','static/js/katex-auto-render.min.js','static/js/katexoptions.js'],'static/js/katexbundle.min.js');
Expand Down Expand Up @@ -254,6 +266,9 @@ function bundle(bpath,js_prestyle,js_switcher,js_email_encode,js_copycode,search
minify_files.push(bpath+'static/js/stork_config.js');
} else if (search_library === 'tinysearch') {
minify_files.push(bpath+'static/js/tinysearch.js');
} else if (search_library === 'pagefind') {
minify_files.push(bpath+'static/js/pagefind.js');
minify_files.push(bpath+'static/js/pagefind.search.js');
}
}
if (pwa) {
Expand Down
3 changes: 2 additions & 1 deletion static/js/abridge.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion static/js/abridge_nopwa.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/js/pagefind-entry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"1.1.0","languages":{"en":{"hash":"en_64251876f7","wasm":"en","page_count":15},"fr":{"hash":"fr_db69a6374e","wasm":"fr","page_count":11},"es":{"hash":"es_d9188c3e85","wasm":"es","page_count":2}}}
Loading

0 comments on commit a7244a2

Please sign in to comment.