From 2c6f5c08beaa73b9d166370a605f9b505f29b480 Mon Sep 17 00:00:00 2001 From: ThArGos Date: Fri, 13 Sep 2024 02:32:03 +0200 Subject: Build the index and copy it next to the search data --- .gitignore | 5 ++++- action.yml | 8 ++++++++ build-index.js | 11 +++++++++++ local.sh | 9 ++++++--- package-lock.json | 9 +++++++++ package.json | 1 + 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 build-index.js diff --git a/.gitignore b/.gitignore index b63e158..e8028e3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ graphdata.json searchdata.json notes/ org-roam-ui/ -out/ \ No newline at end of file +out/ + +# Fuse.js index +fuse-index.json diff --git a/action.yml b/action.yml index af51b3b..b3437df 100644 --- a/action.yml +++ b/action.yml @@ -72,6 +72,14 @@ runs: working-directory: action run: cp --force searchdata.json ../ui/components/Search/ shell: bash + - name: Create Search index + working-directory: action + run: node build-index.js + shell: bash + - name: Copy fuse-index.json to ../ui/components/Search + working-directory: action + run: cp --force fuse-index.json ../ui/components/Search/ + shell: bash - name: Copy org/img to ui/public/ working-directory: action run: | diff --git a/build-index.js b/build-index.js new file mode 100644 index 0000000..e8a8bae --- /dev/null +++ b/build-index.js @@ -0,0 +1,11 @@ +// build-index.js + +const Fuse = require('fuse.js') +const fs = require('fs') +const data = require('./searchdata.json') + +// Create the Fuse index +const myIndex = Fuse.createIndex(['tags', 'title', 'content'], data) + +// Serialize and save it +fs.writeFileSync('fuse-index.json', JSON.stringify(myIndex.toJSON())) diff --git a/local.sh b/local.sh index e6dc7ee..d1be019 100755 --- a/local.sh +++ b/local.sh @@ -1,8 +1,7 @@ #!/bin/bash -# export ROAM_PATH=/path/to/org-roam/src -# export ROAM_DB_FILE=org-roam.db - +read -p "Enter the ROAM_PATH: " ROAM_PATH +read -p "Enter the ROAM_DB_FILE: " ROAM_DB_FILE ROAM_DB_PATH=$ROAM_PATH/$ROAM_DB_FILE ROAM_IMG_PATH=$ROAM_PATH/img @@ -16,9 +15,13 @@ npm install npm run generate:graphdata --script_params=$ROAM_DB_PATH ./create_notes.sh $ROAM_PATH npm run generate:search +npm install fuse.js +node build-index.js # Copy files to the org-roam-ui directory cp -f searchdata.json org-roam-ui/components/Search/ +cp -f fuse-index.json org-roam-ui/components/Search/ + if [ -d $ROAM_IMG_PATH ]; then cp -r $ROAM_IMG_PATH org-roam-ui/public fi diff --git a/package-lock.json b/package-lock.json index fdffa2d..59bc553 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "fuse.js": "^7.0.0", "orgast-util-to-string": "^1.0.1", "sqlite3": "^5.1.7", "unified": "^11.0.4", @@ -434,6 +435,14 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "optional": true }, + "node_modules/fuse.js": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.0.0.tgz", + "integrity": "sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==", + "engines": { + "node": ">=10" + } + }, "node_modules/gauge": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.4.tgz", diff --git a/package.json b/package.json index 44e9bf3..735367d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "author": "", "license": "ISC", "dependencies": { + "fuse.js": "^7.0.0", "orgast-util-to-string": "^1.0.1", "sqlite3": "^5.1.7", "unified": "^11.0.4", -- cgit