1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-06 05:58:36 +00:00
conky/web/utils/doc-utils.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.7 KiB
TypeScript
Raw Normal View History

import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml'
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkGfm from 'remark-gfm'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
const DOC_PATH = path.join(process.cwd(), '..', 'doc')
2022-09-30 17:20:17 -05:00
export interface Documentation {
desc: string
2022-10-01 15:32:01 -05:00
desc_md: string
2022-09-30 17:20:17 -05:00
values: DocItem[]
}
export interface DocItem {
name: string
desc: string
2022-10-01 15:32:01 -05:00
desc_md: string
default: string | undefined
args: string[]
}
2022-09-30 17:20:17 -05:00
function getDocumentation(source: string): Documentation {
const configSettingsFile = fs.readFileSync(
path.join(DOC_PATH, source),
'utf-8'
)
2022-09-30 17:20:17 -05:00
const parsed = yaml.load(configSettingsFile.toString()) as Documentation
const docs = {
2022-10-01 15:32:01 -05:00
...parsed,
desc_md: processMarkdown(parsed.desc),
values: parsed.values.map((c) => ({
...c,
desc_md: processMarkdown(c.desc),
})),
2022-09-30 17:20:17 -05:00
}
return docs
}
2022-10-04 22:37:40 -05:00
export function filterDesc(docs: Documentation): Documentation {
return {
...docs,
desc: '',
values: docs.values.map((v) => ({
...v,
desc: '',
})),
}
}
2022-09-30 17:20:17 -05:00
export function getConfigSettings(): Documentation {
return getDocumentation('config_settings.yaml')
}
2022-09-30 17:20:17 -05:00
export function getVariables(): Documentation {
return getDocumentation('variables.yaml')
}
2022-09-30 17:20:17 -05:00
export function getLua(): Documentation {
return getDocumentation('lua.yaml')
}
function processMarkdown(input: string): string {
return unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeStringify, {allowDangerousHtml: true})
.processSync(input)
.toString()
}