mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-19 21:37:20 +08:00
* feat:提交前端代码 * feat:提交logo样式切换 * feat:替换avatar、部分位置icon、chatchat相关说明、git链接、Wiki链接、关于、设置、反馈与建议等功能,关闭lobehub自检更新功能 * fix:移除多余代码 --------- Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import remarkGfm from 'remark-gfm';
|
|
import remarkParse from 'remark-parse';
|
|
import { unified } from 'unified';
|
|
import { visit } from 'unist-util-visit';
|
|
|
|
import { SPLIT } from './const';
|
|
|
|
export const updateDocs = (path: string, content: string) => {
|
|
const md = readFileSync(path, 'utf8');
|
|
const mds = md.split(SPLIT);
|
|
mds[1] = [' ', content, ' '].join('\n\n');
|
|
const result = mds.join(SPLIT);
|
|
writeFileSync(path, result, 'utf8');
|
|
};
|
|
|
|
export const convertMarkdownToMdast = async (md: string) => {
|
|
// @ts-ignore
|
|
return unified().use(remarkParse).use(remarkGfm).parse(md.trim());
|
|
};
|
|
|
|
export const getTitle = async (path: string) => {
|
|
const md = readFileSync(path, 'utf8');
|
|
const mdast: any = await convertMarkdownToMdast(md);
|
|
|
|
let title = '';
|
|
visit(mdast, 'heading', (node) => {
|
|
if (node.depth !== 1) return;
|
|
visit(node, 'text', (heading) => {
|
|
title += heading.value;
|
|
});
|
|
});
|
|
return title;
|
|
};
|
|
|
|
export const genMdLink = (title: string, url: string) => {
|
|
return `[${title}](${url})`;
|
|
};
|