1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-06-26 10:52:35 +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 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 { getSearchIndex, SearchIndex } from '../utils/search'
@ -27,7 +31,7 @@ export default function ConfigSettings(props: ConfigSettingsProps) {
}
export async function getStaticProps() {
const config_settings = getConfigSettings()
const config_settings = filterDesc(getConfigSettings())
const searchIndex = getSearchIndex()
return { props: { config_settings, searchIndex } }

View File

@ -1,6 +1,6 @@
import Layout from '../components/Layout'
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 { getSearchIndex, SearchIndex } from '../utils/search'
@ -24,7 +24,7 @@ export default function Lua(props: LuaProps) {
}
export async function getStaticProps() {
const lua = getLua()
const lua = filterDesc(getLua())
const searchIndex = getSearchIndex()
return { props: { lua, searchIndex } }

View File

@ -1,6 +1,6 @@
import Layout from '../components/Layout'
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 { getSearchIndex, SearchIndex } from '../utils/search'
@ -27,7 +27,7 @@ export default function Variables(props: VariablesProps) {
}
export async function getStaticProps() {
const variables = getVariables()
const variables = filterDesc(getVariables())
const searchIndex = getSearchIndex()
return { props: { variables, searchIndex } }

View File

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

View File

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