feat: 更新静态资源代理文档,优化路由和插件集成,提升代码可读性和功能性

This commit is contained in:
2026-01-21 01:44:58 +08:00
parent 61add1aad1
commit 7dcf53fb4f
16 changed files with 487 additions and 69 deletions

42
agent/gen.ts Normal file
View File

@@ -0,0 +1,42 @@
import path from 'path';
import glob from 'fast-glob';
async function inlineMarkdownFiles() {
const files: { path: string; name: string }[] = [];
// 添加 readme.md
const readmePath = path.join(import.meta.dir, '..', 'readme.md');
files.push({ path: readmePath, name: 'readme' });
// 使用 fast-glob 动态获取 docs 目录下的 md 文件
const rootDir = path.join(import.meta.dir, '..', 'docs');
const mdFiles = await glob('**.md', { cwd: rootDir });
for (const filename of mdFiles) {
// 将路径转为变量名,如 examples/base -> examples_base
const name = filename.replace(/\.md$/, '').replace(/[^a-zA-Z0-9]/g, '_');
files.push({ path: path.join(rootDir, filename), name });
}
let generatedCode = '// Generated by build script\n';
for (const file of files) {
try {
const content = await Bun.file(file.path).text();
// 转义模板字符串中的特殊字符
const escapedContent = content
.replace(/\\/g, '\\\\')
.replace(/`/g, '\\`')
.replace(/\${/g, '\\${');
generatedCode += `export const ${file.name} = \`${escapedContent}\`;\n`;
} catch (error) {
console.warn(`Failed to read ${file.path}:`, error);
generatedCode += `export const ${file.name} = '';\n`;
}
}
// 写入生成的文件
await Bun.write(path.join(import.meta.dir, 'gen', 'index.ts'), generatedCode);
}
await inlineMarkdownFiles();