1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 20:11:11 +00:00

Improve search index, index page, add wiki link.

This commit is contained in:
Brenden Matthews 2022-10-01 19:00:45 -05:00 committed by Brenden Matthews
parent 1549d7dcce
commit b4cad9a3f7
3 changed files with 49 additions and 37 deletions

View File

@ -17,10 +17,10 @@ interface SearchResultProps {
const SearchResult: React.FunctionComponent<SearchResultProps> = (props) => { const SearchResult: React.FunctionComponent<SearchResultProps> = (props) => {
const excerpt = (s: string) => { const excerpt = (s: string) => {
if (s.length < 100) { if (s.length < 120) {
return <>{s}</> return <>{s}</>
} else { } else {
return <>{s.substring(0, 100)}&hellip;</> return <>{s.substring(0, 120)}&hellip;</>
} }
} }
const bg_for = (s: string) => { const bg_for = (s: string) => {

View File

@ -4,6 +4,7 @@ import Layout from '../components/Layout'
import ArrowIcon from '../components/ArrowIcon' import ArrowIcon from '../components/ArrowIcon'
import SEO from '../components/SEO' import SEO from '../components/SEO'
import { getSearchIndex, SearchIndex } from '../utils/search' import { getSearchIndex, SearchIndex } from '../utils/search'
import { Url } from 'url'
const pages = [ const pages = [
{ {
@ -23,6 +24,29 @@ const pages = [
}, },
] ]
interface IndexItemProps {
href: string
as?: string
title: string
desc?: string
}
const IndexItem: React.FunctionComponent<IndexItemProps> = (props) => {
return (
<div className="md:first:rounded-t-lg md:last:rounded-b-lg backdrop-blur-lg bg-slate-300 dark:bg-black dark:bg-opacity-30 bg-opacity-10 hover:bg-opacity-30 dark:hover:bg-opacity-50 transition border border-gray-800 dark:border-white border-opacity-10 dark:border-opacity-10 border-b-0 last:border-b hover:border-b hovered-sibling:border-t-0">
<Link as={props.as} href={props.href}>
<a className="py-2 lg:py-4 px-2 lg:px-4 block focus:outline-none focus:ring-4">
<h2 className="text-xl md:text-2xl">{props.title}</h2>
{props.desc && (
<p className="mt-3 text-lg opacity-60">{props.desc}</p>
)}
<ArrowIcon className="mt-4" />
</a>
</Link>
</div>
)
}
interface IndexProps { interface IndexProps {
documents: Document[] documents: Document[]
searchIndex: SearchIndex searchIndex: SearchIndex
@ -35,42 +59,27 @@ export default function Index({ documents, searchIndex }: IndexProps) {
<main className="w-full"> <main className="w-full">
<div className="w-full"> <div className="w-full">
{pages.map((p) => ( {pages.map((p) => (
<div <IndexItem
key={p.slug} key={p.slug}
className="md:first:rounded-t-lg md:last:rounded-b-lg backdrop-blur-lg bg-slate-300 dark:bg-black dark:bg-opacity-30 bg-opacity-10 hover:bg-opacity-30 dark:hover:bg-opacity-50 transition border border-gray-800 dark:border-white border-opacity-10 dark:border-opacity-10 border-b-0 last:border-b hover:border-b hovered-sibling:border-t-0" href={p.slug}
> title={p.title}
<Link as={p.slug} href={p.slug}> desc={p.desc}
<a className="py-6 lg:py-10 px-6 lg:px-16 block focus:outline-none focus:ring-4"> />
<h2 className="text-2xl md:text-3xl">{p.title}</h2>
<p className="mt-3 text-lg opacity-60">{p.desc}</p>
<ArrowIcon className="mt-4" />
</a>
</Link>
</div>
))} ))}
{documents.map((document) => ( {documents.map((document) => (
<div <IndexItem
key={document.filePath} key={document.filePath}
className="md:first:rounded-t-lg md:last:rounded-b-lg backdrop-blur-lg bg-slate-300 dark:bg-black dark:bg-opacity-30 bg-opacity-10 hover:bg-opacity-30 dark:hover:bg-opacity-50 transition border border-gray-800 dark:border-white border-opacity-10 dark:border-opacity-10 border-b-0 last:border-b hover:border-b hovered-sibling:border-t-0" as={`/documents/${document.filePath.replace(/\.mdx?$/, '')}`}
> href={`/documents/[slug]`}
<Link title={document.data.title}
as={`/documents/${document.filePath.replace(/\.mdx?$/, '')}`} desc={document.data.description}
href={`/documents/[slug]`} />
>
<a className="py-6 lg:py-10 px-6 lg:px-16 block focus:outline-none focus:ring-4">
<h2 className="text-2xl md:text-3xl">
{document.data.title}
</h2>
{document.data.description && (
<p className="mt-3 text-lg opacity-60">
{document.data.description}
</p>
)}
<ArrowIcon className="mt-4" />
</a>
</Link>
</div>
))} ))}
<IndexItem
href="https://github.com/brndnmtthws/conky/wiki"
title="Wiki"
desc="The Wiki (hosted on GitHub) contains a number of user configs, Lua scripts, FAQs and more."
/>
</div> </div>
</main> </main>
</Layout> </Layout>

View File

@ -17,22 +17,25 @@ export function getSearchIndex() {
const cs: SearchItem[] = getConfigSettings().values.map((v) => ({ const cs: SearchItem[] = getConfigSettings().values.map((v) => ({
kind: 'config', kind: 'config',
name: v.name, name: v.name,
desc: v.desc.substring(0, 200), desc: v.desc,
})) }))
const vars: SearchItem[] = getVariables().values.map((v) => ({ const vars: SearchItem[] = getVariables().values.map((v) => ({
kind: 'var', kind: 'var',
name: v.name, name: v.name,
desc: v.desc.substring(0, 200), desc: v.desc,
})) }))
const lua: SearchItem[] = getLua().values.map((v) => ({ const lua: SearchItem[] = getLua().values.map((v) => ({
kind: 'lua', kind: 'lua',
name: v.name, name: v.name,
desc: v.desc.substring(0, 200), desc: v.desc,
})) }))
const list: SearchItem[] = [...cs, ...vars, ...lua] const list: SearchItem[] = [...cs, ...vars, ...lua]
return { return {
list, list: list.map((item) => ({
...item,
desc: item.desc.substring(0, 121),
})),
index: Fuse.createIndex<SearchItem>(['name', 'desc'], list).toJSON(), index: Fuse.createIndex<SearchItem>(['name', 'desc'], list).toJSON(),
} }
} }