mirror of
https://github.com/cupcakearmy/nicco.io.git
synced 2024-12-22 08:06:29 +00:00
search
This commit is contained in:
parent
94df60aa08
commit
2c97126b56
@ -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(' '),
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -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 = []
|
||||
|
Loading…
Reference in New Issue
Block a user