@@ -76,6 +79,7 @@ export default function Index({ documents }: IndexProps) {
export function getStaticProps() {
const documents = getDocuments()
+ const searchIndex = getSearchIndex()
- return { props: { documents } }
+ return { props: { documents, searchIndex } }
}
diff --git a/web/pages/lua.tsx b/web/pages/lua.tsx
index 507a8043..2b84cade 100644
--- a/web/pages/lua.tsx
+++ b/web/pages/lua.tsx
@@ -2,14 +2,16 @@ import Layout from '../components/Layout'
import SEO from '../components/SEO'
import { getLua, Documentation } from '../utils/doc-utils'
import Docs from '../components/Docs'
+import { getSearchIndex, SearchIndex } from '../utils/search'
export interface LuaProps {
lua: Documentation
+ searchIndex: SearchIndex
}
export default function Lua(props: LuaProps) {
return (
-
+
@@ -23,6 +25,7 @@ export default function Lua(props: LuaProps) {
export async function getStaticProps() {
const lua = getLua()
+ const searchIndex = getSearchIndex()
- return { props: { lua } }
+ return { props: { lua, searchIndex } }
}
diff --git a/web/pages/variables.tsx b/web/pages/variables.tsx
index b63ba27c..a5645fbf 100644
--- a/web/pages/variables.tsx
+++ b/web/pages/variables.tsx
@@ -2,14 +2,16 @@ import Layout from '../components/Layout'
import SEO from '../components/SEO'
import { getVariables, Documentation } from '../utils/doc-utils'
import Docs from '../components/Docs'
+import { getSearchIndex, SearchIndex } from '../utils/search'
export interface VariablesProps {
variables: Documentation
+ searchIndex: SearchIndex
}
export default function Variables(props: VariablesProps) {
return (
-
+
({ ...c, desc: processMarkdown(c.desc) })),
+ ...parsed,
+ desc_md: processMarkdown(parsed.desc),
+ values: parsed.values.map((c) => ({
+ ...c,
+ desc_md: processMarkdown(c.desc),
+ })),
}
return docs
diff --git a/web/utils/search.ts b/web/utils/search.ts
new file mode 100644
index 00000000..80c4c508
--- /dev/null
+++ b/web/utils/search.ts
@@ -0,0 +1,38 @@
+import Fuse from 'fuse.js'
+import { getConfigSettings, getLua, getVariables } from './doc-utils'
+export interface SearchItem {
+ kind: string
+ name: string
+ desc: string
+}
+export interface SearchIndex {
+ index: {
+ keys: readonly string[]
+ records: Fuse.FuseIndexRecords
+ }
+ list: SearchItem[]
+}
+
+export function getSearchIndex() {
+ const cs: SearchItem[] = getConfigSettings().values.map((v) => ({
+ kind: 'config',
+ name: v.name,
+ desc: v.desc.substring(0, 200),
+ }))
+ const vars: SearchItem[] = getVariables().values.map((v) => ({
+ kind: 'var',
+ name: v.name,
+ desc: v.desc.substring(0, 200),
+ }))
+ const lua: SearchItem[] = getLua().values.map((v) => ({
+ kind: 'lua',
+ name: v.name,
+ desc: v.desc.substring(0, 200),
+ }))
+ const list: SearchItem[] = [...cs, ...vars, ...lua]
+
+ return {
+ list,
+ index: Fuse.createIndex(['name', 'desc'], list).toJSON(),
+ }
+}
diff --git a/web/yarn.lock b/web/yarn.lock
index 94a18fd0..a635862d 100644
--- a/web/yarn.lock
+++ b/web/yarn.lock
@@ -124,6 +124,11 @@
resolved "https://registry.yarnpkg.com/@fontsource/source-serif-pro/-/source-serif-pro-4.5.9.tgz#fbeacd0bb6d2860df6baa662e9827adfe3da13f4"
integrity sha512-VgDvUvd3An3v9HtKgYk9TJuhB/4ZXw4huv/uqTXO4gES7CUbqGcf6tSb69TwG6o5AZzEVt6jnN7FN18OaO5J9A==
+"@headlessui/react@^1.7.3":
+ version "1.7.3"
+ resolved "https://registry.yarnpkg.com/@headlessui/react/-/react-1.7.3.tgz#853c598ff47b37cdd192c5cbee890d9b610c3ec0"
+ integrity sha512-LGp06SrGv7BMaIQlTs8s2G06moqkI0cb0b8stgq7KZ3xcHdH3qMP+cRyV7qe5x4XEW/IGY48BW4fLesD6NQLng==
+
"@humanwhocodes/config-array@^0.10.5":
version "0.10.5"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.10.5.tgz#bb679745224745fff1e9a41961c1d45a49f81c04"
@@ -3398,6 +3403,11 @@ functions-have-names@^1.2.2:
resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
+fuse.js@^6.6.2:
+ version "6.6.2"
+ resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-6.6.2.tgz#fe463fed4b98c0226ac3da2856a415576dc9a111"
+ integrity sha512-cJaJkxCCxC8qIIcPBF9yGxY0W/tVZS3uEISDxhYIdtk8OL93pe+6Zj7LjCqVV4dzbqcriOZ+kQ/NE4RXZHsIGA==
+
get-caller-file@^2.0.0, get-caller-file@^2.0.1:
version "2.0.5"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"