Пересобранный и видоизмененный conky для ОСГОС

This commit is contained in:
commit 3a48cf8c86
738 changed files with 217718 additions and 0 deletions

73
web/utils/doc-utils.ts Normal file
View file

@ -0,0 +1,73 @@
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 Documentation {
desc: string
desc_md: string
values: DocItem[]
}
export interface DocItem {
name: string
desc: string
desc_md: string
default: string | undefined
args: string[]
}
function getDocumentation(source: string): Documentation {
const configSettingsFile = fs.readFileSync(
path.join(DOC_PATH, source),
'utf-8'
)
const parsed = yaml.load(configSettingsFile.toString()) as Documentation
const docs = {
...parsed,
desc_md: processMarkdown(parsed.desc),
values: parsed.values.map((c) => ({
...c,
desc_md: processMarkdown(c.desc),
})),
}
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')
}
export function getVariables(): Documentation {
return getDocumentation('variables.yaml')
}
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()
}

113
web/utils/mdx-utils.ts Normal file
View file

@ -0,0 +1,113 @@
import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { unified } from 'unified'
import remarkGfm from 'remark-gfm'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
// DOCUMENTS_PATH is useful when you want to get the path to a specific file
export const DOCUMENTS_PATH = path.join(process.cwd(), 'documents')
// documentFilePaths is the list of all mdx files inside the DOCUMENTS_PATH directory
export const documentFilePaths = fs
.readdirSync(DOCUMENTS_PATH)
// Only include md(x) files
.filter((path) => /\.mdx?$/.test(path))
export interface DocumentData {
title?: string
description?: string
indexWeight?: number
}
export interface Document {
content: string
data: DocumentData
filePath: string
}
export const getDocuments = (): Document[] => {
const documents = documentFilePaths.map((filePath) => {
const source = fs.readFileSync(path.join(DOCUMENTS_PATH, filePath), 'utf-8')
const { content, data } = matter(source)
return {
content,
data,
filePath,
}
})
documents.sort((a, b) => {
if (a.data.indexWeight > b.data.indexWeight) {
return 1
}
if (a.data.indexWeight < b.data.indexWeight) {
return -1
}
return a.data.title.localeCompare(b.data.title)
})
return documents
}
export const getDocumentBySlug = async (slug: string) => {
const documentFilePath = path.join(DOCUMENTS_PATH, `${slug}.mdx`)
const source = fs.readFileSync(documentFilePath, 'utf-8')
const { content, data } = matter(source)
const result = await unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype, {allowDangerousHtml: true})
// .use(rehypePrism)
.use(rehypeStringify, {allowDangerousHtml: true})
.process(content)
return { source: result.value, data, documentFilePath }
}
export const getNextDocumentBySlug = (slug: string) => {
const documents = getDocuments()
const currentFileName = `${slug}.mdx`
const currentDocument = documents.find(
(document) => document.filePath === currentFileName
)
if (!currentDocument) return null
const currentDocumentIndex = documents.indexOf(currentDocument)
const document = documents[currentDocumentIndex - 1]
// no prev document found
if (!document) return null
const nextDocumentSlug = document?.filePath.replace(/\.mdx?$/, '')
return {
title: document.data.title,
slug: nextDocumentSlug,
}
}
export const getPreviousDocumentBySlug = (slug: string) => {
const documents = getDocuments()
const currentFileName = `${slug}.mdx`
const currentDocument = documents.find(
(document) => document.filePath === currentFileName
)
if (!currentDocument) return null
const currentDocumentIndex = documents.indexOf(currentDocument)
const document = documents[currentDocumentIndex + 1]
// no prev document found
if (!document) return null
const previousDocumentSlug = document?.filePath.replace(/\.mdx?$/, '')
return {
title: document.data.title,
slug: previousDocumentSlug,
}
}

View file

@ -0,0 +1,9 @@
import * as fs from 'fs/promises'
import { createSearchIndex } from './search'
export async function writeSearchIndex() {
await fs.mkdir('public').catch(() => {})
await fs.mkdir('public/static').catch(() => {})
const index = createSearchIndex()
await fs.writeFile('public/static/fuse-index.json', JSON.stringify(index))
}

40
web/utils/search.ts Normal file
View file

@ -0,0 +1,40 @@
import Fuse, { FuseIndexRecords } from 'fuse.js'
import { getConfigSettings, getLua, getVariables } from './doc-utils'
export interface SearchItem {
kind: string
name: string
desc: string
}
export interface SearchIndex {
index: {
keys: readonly string[]
records: FuseIndexRecords
}
list: SearchItem[]
}
export function createSearchIndex(): SearchIndex {
const cs: SearchItem[] = getConfigSettings().values.map((v) => ({
kind: 'config',
name: v.name,
desc: v.desc.substring(0, 121),
}))
const vars: SearchItem[] = getVariables().values.map((v) => ({
kind: 'var',
name: v.name,
desc: v.desc.substring(0, 121),
}))
const lua: SearchItem[] = getLua().values.map((v) => ({
kind: 'lua',
name: v.name,
desc: v.desc.substring(0, 121),
}))
const list: SearchItem[] = [...cs, ...vars, ...lua]
return {
list,
index: Fuse.createIndex<SearchItem>(['name', 'desc'], list).toJSON(),
}
}

View file

@ -0,0 +1,79 @@
import plugin = require('tailwindcss/plugin')
import pluginTypography = require('@tailwindcss/typography')
const hoveredSiblingPlugin = plugin(function ({ addVariant, e }) {
addVariant('hovered-sibling', ({ container }) => {
container.walkRules((rule) => {
rule.selector = `:hover + .hovered-sibling\\:${rule.selector.slice(1)}`
})
})
})
module.exports = {
theme: {
fontFamily: {
sans: [
'Inter Variable',
'ui-sans-serif',
'system-ui',
'-apple-system',
'BlinkMacSystemFont',
'Segoe UI',
'Roboto',
'Helvetica Neue',
'Arial',
'Noto Sans',
'sans-serif',
'Apple Color Emoji',
'Segoe UI Emoji',
'Segoe UI Symbol',
'Noto Color Emoji',
],
serif: [
'Newsreader Variable',
'ui-serif',
'Georgia',
'Cambria',
'Times New Roman',
'Times',
'serif',
],
mono: [
'Fira Code Variable',
'ui-monospace',
'SFMono-Regular',
'Menlo',
'Monaco',
'Consolas',
'Liberation Mono',
'Courier New',
'monospace',
],
},
extend: {
typography: (theme) => ({
DEFAULT: {
css: {
code: {
'&::before': {
content: '"" !important',
},
'&::after': {
content: '"" !important',
},
},
fontFamily: theme('fontFamily.sans').join(', '),
},
},
}),
},
},
variants: {
extend: {
borderRadius: ['first', 'last'],
borderWidth: ['last', 'hovered-sibling'],
typography: ['dark'],
},
},
plugins: [hoveredSiblingPlugin, pluginTypography],
}