From 436fdf54243c59f9b735101103dfa0d338b08558 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 22 Feb 2022 18:39:25 +0100 Subject: [PATCH] wip #5120 --- app/Jobs/SearchIndex.php | 5 +---- package-lock.json | 15 ++++++++++++++- package.json | 3 +++ resources/js/search.js | 15 ++++++++------- resources/views/components/search.blade.php | 2 +- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/Jobs/SearchIndex.php b/app/Jobs/SearchIndex.php index 87251ce..3f71a8a 100644 --- a/app/Jobs/SearchIndex.php +++ b/app/Jobs/SearchIndex.php @@ -3,9 +3,6 @@ namespace App\Jobs; use App\Models\Asset; -use App\Models\Resource; -use App\Models\Tour; -use Cubist\Backpack\Magic\PageData; use Cubist\Minisearch\Document; use Cubist\Minisearch\Document\PDF; use Cubist\Minisearch\Index; @@ -16,7 +13,7 @@ class SearchIndex extends Index public function __construct() { - $this->output = public_path('js/search.index.js'); + $this->output = public_path('js/search.index.json'); } public function handle() diff --git a/package-lock.json b/package-lock.json index ba9cbdf..cecb0d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,12 @@ { - "name": "www", + "name": "ODL", "lockfileVersion": 2, "requires": true, "packages": { "": { + "dependencies": { + "fs": "^0.0.1-security" + }, "devDependencies": { "@alpinejs/intersect": "^3.4.2", "@tailwindcss/line-clamp": "^0.2.2", @@ -4715,6 +4718,11 @@ "node": ">= 0.6" } }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, "node_modules/fs-extra": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", @@ -13394,6 +13402,11 @@ "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", "dev": true }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, "fs-extra": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", diff --git a/package.json b/package.json index 0a4a6de..d4101d6 100644 --- a/package.json +++ b/package.json @@ -25,5 +25,8 @@ "postcss-import": "^14.0.2", "smooth-scroll": "^16.1.3", "tailwindcss": "^3.0.15" + }, + "dependencies": { + "fs": "^0.0.1-security" } } diff --git a/resources/js/search.js b/resources/js/search.js index 24c1803..455e1f8 100644 --- a/resources/js/search.js +++ b/resources/js/search.js @@ -3,6 +3,7 @@ //=====================// import MiniSearch from 'minisearch'; +import {readFile} from 'fs' export default () => ({ @@ -19,13 +20,13 @@ export default () => ({ async init() { // We need the URL from the HTML because it gets properly updated when exporting the final version - await loadScript(this.$el.dataset.searchindex); - - // Delay miniSearch initialisation so there's less chance of animations stuttering during page loads - setTimeout(() => { - window.minisearch = this.miniSearch = new MiniSearch(this.setup); - this.miniSearch.addAllAsync(minisearchodl); - }, 4000); + readFile(this.$el.dataset.searchindex, function (err, data) { + // Delay miniSearch initialisation so there's less chance of animations stuttering during page loads + setTimeout(() => { + window.minisearch = this.miniSearch = new MiniSearch(); + this.miniSearch.loadJSON(data, this.setup) + }, 4000); + }); this.medialibrary = this.$el.dataset.medialibrary; }, diff --git a/resources/views/components/search.blade.php b/resources/views/components/search.blade.php index bffa838..26b3751 100644 --- a/resources/views/components/search.blade.php +++ b/resources/views/components/search.blade.php @@ -4,7 +4,7 @@ bg-white text-black z-20" {{-- Pass URLs in from HTML so JS will always have the correct version regardless of environment --}} - data-searchindex="{{ asset('js/search.index.js') }}" + data-searchindex="{{ asset('js/search.index.json') }}" data-medialibrary="{{ \App\Http\Controllers\FrontController::getLinkData('medialibrary')['url'] }}" {{-- See js/search.js --}} x-data="search()" -- 2.39.5