From b4cad9a3f742c078879945299d5db2ed12466fca Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 1 Oct 2022 19:00:45 -0500 Subject: [PATCH] Improve search index, index page, add wiki link. --- web/components/Search.tsx | 4 +-- web/pages/index.tsx | 71 ++++++++++++++++++++++----------------- web/utils/search.ts | 11 +++--- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/web/components/Search.tsx b/web/components/Search.tsx index 229fb1fc..eabf39c4 100644 --- a/web/components/Search.tsx +++ b/web/components/Search.tsx @@ -17,10 +17,10 @@ interface SearchResultProps { const SearchResult: React.FunctionComponent = (props) => { const excerpt = (s: string) => { - if (s.length < 100) { + if (s.length < 120) { return <>{s} } else { - return <>{s.substring(0, 100)}… + return <>{s.substring(0, 120)}… } } const bg_for = (s: string) => { diff --git a/web/pages/index.tsx b/web/pages/index.tsx index 64566067..594fdcf3 100644 --- a/web/pages/index.tsx +++ b/web/pages/index.tsx @@ -4,6 +4,7 @@ import Layout from '../components/Layout' import ArrowIcon from '../components/ArrowIcon' import SEO from '../components/SEO' import { getSearchIndex, SearchIndex } from '../utils/search' +import { Url } from 'url' const pages = [ { @@ -23,6 +24,29 @@ const pages = [ }, ] +interface IndexItemProps { + href: string + as?: string + title: string + desc?: string +} + +const IndexItem: React.FunctionComponent = (props) => { + return ( +
+ + +

{props.title}

+ {props.desc && ( +

{props.desc}

+ )} + +
+ +
+ ) +} + interface IndexProps { documents: Document[] searchIndex: SearchIndex @@ -35,42 +59,27 @@ export default function Index({ documents, searchIndex }: IndexProps) {
{pages.map((p) => ( - + href={p.slug} + title={p.title} + desc={p.desc} + /> ))} {documents.map((document) => ( - + as={`/documents/${document.filePath.replace(/\.mdx?$/, '')}`} + href={`/documents/[slug]`} + title={document.data.title} + desc={document.data.description} + /> ))} +
diff --git a/web/utils/search.ts b/web/utils/search.ts index 80c4c508..c59fbfa6 100644 --- a/web/utils/search.ts +++ b/web/utils/search.ts @@ -17,22 +17,25 @@ export function getSearchIndex() { const cs: SearchItem[] = getConfigSettings().values.map((v) => ({ kind: 'config', name: v.name, - desc: v.desc.substring(0, 200), + desc: v.desc, })) const vars: SearchItem[] = getVariables().values.map((v) => ({ kind: 'var', name: v.name, - desc: v.desc.substring(0, 200), + desc: v.desc, })) const lua: SearchItem[] = getLua().values.map((v) => ({ kind: 'lua', name: v.name, - desc: v.desc.substring(0, 200), + desc: v.desc, })) const list: SearchItem[] = [...cs, ...vars, ...lua] return { - list, + list: list.map((item) => ({ + ...item, + desc: item.desc.substring(0, 121), + })), index: Fuse.createIndex(['name', 'desc'], list).toJSON(), } }