-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
95 lines (81 loc) · 1.98 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<script setup>
/** Vendor */
import { Document } from "@akryum/flexsearch-es"
/** Utils */
import { parseArticles } from "@/utils/search"
/** Store */
import { useSearchStore } from "@/store/search"
const searchStore = useSearchStore()
onMounted(async () => {
const articles = await queryContent("/").find()
const parsedArticles = parseArticles(articles)
searchStore.indexes.page = new Document({
cache: 100,
tokenize: "full",
document: {
id: "id",
index: "content",
store: ["title"],
},
context: {
resolution: 9,
depth: 2,
bidirectional: true,
},
})
searchStore.indexes.section = new Document({
cache: 100,
tokenize: "full",
document: {
id: "id",
index: "content",
tag: "pageId",
store: ["title", "content", "url", "display"],
},
context: {
resolution: 9,
depth: 2,
bidirectional: true,
},
})
searchStore.isIndexed = true
Object.keys(parsedArticles).forEach(async (pageId) => {
const page = parsedArticles[pageId]
await searchStore.indexes.page.addAsync({
id: pageId,
title: page.title,
content: `${page.title} ${page.plainText}`,
})
Object.keys(page.sections).forEach(async (sectionId) => {
const section = page.sections[sectionId]
const paragraphs = section.content.split("\n").filter(Boolean)
await searchStore.indexes.section.addAsync({
id: `${page.path}#${sectionId}@s`,
url: page.path,
title: section.title,
pageId: `pg_${pageId}`,
content: section.title,
...(paragraphs[0] && { display: paragraphs[0] }),
})
paragraphs.forEach(async (paragraph, idx) => {
await searchStore.indexes.section.addAsync({
id: `${page.path}#${sectionId}@${idx}`,
url: page.path,
title: section.title,
pageId: `pg_${pageId}`,
content: paragraph,
})
})
})
})
})
</script>
<template>
<NuxtLoadingIndicator :height="2" color="#0ade71" />
<NuxtLayout>
<NuxtPage />
<div id="tooltip" />
<div id="dropdown" />
<!-- <Notifications /> -->
</NuxtLayout>
</template>