mirror of
https://github.com/cupcakearmy/nicco.io.git
synced 2024-12-22 16:16:24 +00:00
search
This commit is contained in:
parent
94df60aa08
commit
2c97126b56
@ -8,10 +8,10 @@ function removeHTML(s) {
|
|||||||
|
|
||||||
async function convertForIdx(type, fields = []) {
|
async function convertForIdx(type, fields = []) {
|
||||||
const items = await getAll(type)
|
const items = await getAll(type)
|
||||||
const defaults = ['title', 'content', 'slug']
|
const keys = ['title', 'content', 'slug', ...fields]
|
||||||
return items.map((item) => ({
|
return items.map((item) => ({
|
||||||
url: `${item.type}/${item.slug}`,
|
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">
|
<script context="module">
|
||||||
import lunr from 'lunr'
|
|
||||||
|
|
||||||
export async function preload({ query }) {
|
export async function preload({ query }) {
|
||||||
const prebuilt = await this.fetch(`/search.json`).then((res) => res.json())
|
const prebuilt = await this.fetch(`/search.json`).then((res) => res.json())
|
||||||
return { idx: lunr.Index.load(prebuilt) }
|
return { prebuilt }
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import lunr from 'lunr'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
|
||||||
import SearchResult from '../components/SearchResult.svelte'
|
import SearchResult from '../components/SearchResult.svelte'
|
||||||
import SimplePage from '../components/SimplePage.svelte'
|
import SimplePage from '../components/SimplePage.svelte'
|
||||||
|
|
||||||
export let idx
|
export let prebuilt
|
||||||
let needle
|
let needle
|
||||||
let results = []
|
let results = []
|
||||||
|
|
||||||
|
const idx = lunr.Index.load(prebuilt)
|
||||||
|
|
||||||
async function search(needle) {
|
async function search(needle) {
|
||||||
if (!needle || !idx) {
|
if (!needle || !idx) {
|
||||||
results = []
|
results = []
|
||||||
|
Loading…
Reference in New Issue
Block a user