1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-19 19:45:15 +00:00
conky/web/utils/doc-utils.ts

50 lines
1.2 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')
export interface Doc {
name: string
desc: string
default: string | undefined
args: string[]
}
function getDocumentation(source: string): Doc[] {
const configSettingsFile = fs.readFileSync(
path.join(DOC_PATH, source),
'utf-8'
)
const parsed = yaml.load(configSettingsFile.toString()) as Doc[]
const docs = parsed.map((c) => ({ ...c, desc: processMarkdown(c.desc) }))
return docs
}
export function getConfigSettings(): Doc[] {
return getDocumentation('config_settings.yaml')
}
export function getVariables(): Doc[] {
return getDocumentation('variables.yaml')
}
export function getLua(): Doc[] {
return getDocumentation('lua.yaml')
}
function processMarkdown(input: string): string {
return unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeStringify)
.processSync(input)
.toString()
}