This commit is contained in:
cupcakearmy 2021-01-27 13:01:26 +01:00
parent 94df60aa08
commit 2c97126b56
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
2 changed files with 7 additions and 6 deletions

View File

@ -8,10 +8,10 @@ function removeHTML(s) {
async function convertForIdx(type, fields = []) {
const items = await getAll(type)
const defaults = ['title', 'content', 'slug']
const keys = ['title', 'content', 'slug', ...fields]
return items.map((item) => ({
url: `${item.type}/${item.slug}`,
data: [...defaults, ...fields].map((field) => removeHTML(item[field])).join(' '),
data: keys.map((field) => removeHTML(item[field])).join(' '),
}))
}

View File

@ -1,22 +1,23 @@
<script context="module">
import lunr from 'lunr'
export async function preload({ query }) {
const prebuilt = await this.fetch(`/search.json`).then((res) => res.json())
return { idx: lunr.Index.load(prebuilt) }
return { prebuilt }
}
</script>
<script>
import lunr from 'lunr'
import { onMount } from 'svelte'
import SearchResult from '../components/SearchResult.svelte'
import SimplePage from '../components/SimplePage.svelte'
export let idx
export let prebuilt
let needle
let results = []
const idx = lunr.Index.load(prebuilt)
async function search(needle) {
if (!needle || !idx) {
results = []