mirror of
https://github.com/PaiGramTeam/PaiGramDocs.git
synced 2024-11-23 00:11:32 +00:00
33 lines
880 B
TypeScript
33 lines
880 B
TypeScript
|
import { resolve } from 'node:path'
|
||
|
import Git from 'simple-git'
|
||
|
|
||
|
export const git = Git()
|
||
|
|
||
|
export const DOCS_URL = 'https://docs.paimon.vip/'
|
||
|
|
||
|
export const DIR_ROOT = resolve(__dirname, '..')
|
||
|
export const DIR_SRC = resolve(__dirname, '../docs')
|
||
|
|
||
|
export function replacer(code: string, value: string, key: string, insert: 'head' | 'tail' | 'none' = 'none') {
|
||
|
const START = `<!--${key}_STARTS-->`
|
||
|
const END = `<!--${key}_ENDS-->`
|
||
|
const regex = new RegExp(`${START}[\\s\\S]*?${END}`, 'im')
|
||
|
|
||
|
const target = value ? `${START}\n${value}\n${END}` : `${START}${END}`
|
||
|
|
||
|
if (!code.match(regex)) {
|
||
|
if (insert === 'none')
|
||
|
return code
|
||
|
else if (insert === 'head')
|
||
|
return `${target}\n\n${code}`
|
||
|
else
|
||
|
return `${code}\n\n${target}`
|
||
|
}
|
||
|
|
||
|
return code.replace(regex, target)
|
||
|
}
|
||
|
|
||
|
export function uniq<T extends any[]>(a: T) {
|
||
|
return Array.from(new Set(a))
|
||
|
}
|