1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-10 16:08:31 +00:00

Optimize static props a bit.

This commit is contained in:
Brenden Matthews 2022-10-04 22:37:40 -05:00 committed by Brenden Matthews
parent 1051acbe88
commit ec8981c5da
5 changed files with 25 additions and 13 deletions

View File

@ -1,6 +1,10 @@
import Layout from '../components/Layout' import Layout from '../components/Layout'
import SEO from '../components/SEO' import SEO from '../components/SEO'
import { getConfigSettings, Documentation } from '../utils/doc-utils' import {
getConfigSettings,
Documentation,
filterDesc,
} from '../utils/doc-utils'
import Docs from '../components/Docs' import Docs from '../components/Docs'
import { getSearchIndex, SearchIndex } from '../utils/search' import { getSearchIndex, SearchIndex } from '../utils/search'
@ -27,7 +31,7 @@ export default function ConfigSettings(props: ConfigSettingsProps) {
} }
export async function getStaticProps() { export async function getStaticProps() {
const config_settings = getConfigSettings() const config_settings = filterDesc(getConfigSettings())
const searchIndex = getSearchIndex() const searchIndex = getSearchIndex()
return { props: { config_settings, searchIndex } } return { props: { config_settings, searchIndex } }

View File

@ -1,6 +1,6 @@
import Layout from '../components/Layout' import Layout from '../components/Layout'
import SEO from '../components/SEO' import SEO from '../components/SEO'
import { getLua, Documentation } from '../utils/doc-utils' import { getLua, Documentation, filterDesc } from '../utils/doc-utils'
import Docs from '../components/Docs' import Docs from '../components/Docs'
import { getSearchIndex, SearchIndex } from '../utils/search' import { getSearchIndex, SearchIndex } from '../utils/search'
@ -24,7 +24,7 @@ export default function Lua(props: LuaProps) {
} }
export async function getStaticProps() { export async function getStaticProps() {
const lua = getLua() const lua = filterDesc(getLua())
const searchIndex = getSearchIndex() const searchIndex = getSearchIndex()
return { props: { lua, searchIndex } } return { props: { lua, searchIndex } }

View File

@ -1,6 +1,6 @@
import Layout from '../components/Layout' import Layout from '../components/Layout'
import SEO from '../components/SEO' import SEO from '../components/SEO'
import { getVariables, Documentation } from '../utils/doc-utils' import { getVariables, Documentation, filterDesc } from '../utils/doc-utils'
import Docs from '../components/Docs' import Docs from '../components/Docs'
import { getSearchIndex, SearchIndex } from '../utils/search' import { getSearchIndex, SearchIndex } from '../utils/search'
@ -27,7 +27,7 @@ export default function Variables(props: VariablesProps) {
} }
export async function getStaticProps() { export async function getStaticProps() {
const variables = getVariables() const variables = filterDesc(getVariables())
const searchIndex = getSearchIndex() const searchIndex = getSearchIndex()
return { props: { variables, searchIndex } } return { props: { variables, searchIndex } }

View File

@ -40,6 +40,17 @@ function getDocumentation(source: string): Documentation {
return docs return docs
} }
export function filterDesc(docs: Documentation): Documentation {
return {
...docs,
desc: '',
values: docs.values.map((v) => ({
...v,
desc: '',
})),
}
}
export function getConfigSettings(): Documentation { export function getConfigSettings(): Documentation {
return getDocumentation('config_settings.yaml') return getDocumentation('config_settings.yaml')
} }

View File

@ -17,25 +17,22 @@ 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, desc: v.desc.substring(0, 121),
})) }))
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, desc: v.desc.substring(0, 121),
})) }))
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, desc: v.desc.substring(0, 121),
})) }))
const list: SearchItem[] = [...cs, ...vars, ...lua] const list: SearchItem[] = [...cs, ...vars, ...lua]
return { return {
list: list.map((item) => ({ list,
...item,
desc: item.desc.substring(0, 121),
})),
index: Fuse.createIndex<SearchItem>(['name', 'desc'], list).toJSON(), index: Fuse.createIndex<SearchItem>(['name', 'desc'], list).toJSON(),
} }
} }