- 首页:`/` 未登录原地显示登录页(不再跳 /login),已登录直接进 `/dashboard`; 看板路由由 `/` 迁到 `/dashboard`,侧边栏「首页」与无权限回跳同步; 桌面端「工具 → 打开配置页」的 `/?token=` 免登录仍然可用 - 文档站:`/doc/**` 由后端整站生成静态 HTML(顶部分类 tab 全局切换、左侧栏目 → 内容页、 右侧本页目录);`/sitemap.txt` 新链接追加到末尾,下架 / 删除的会被清理 - 平台管理 · 文档管理(`/admin/doc`):分类 / 栏目 / 内容页(Markdown)简易 CMS, 内容页有编辑表单与列表,保存后自动重生成目录与静态页面 - 登录页右下角、顶栏(登录后)、看板右上角新增进入文档站的链接 - 部署:nginx 模板为 `/doc`、`/doc/`、`/sitemap.txt` 增加反代(否则会落到 SPA 回退); Vite dev server 增加同名代理;`middleware/frontend.js` 排除这些路径 - 登录页插画改为内联 SVG(沿用工作区已有的未提交改动) - 测试:新增 Markdown 渲染单测;后端 218 个用例通过,前端 typecheck / build 通过 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
'use strict';
|
||
|
||
const assert = require('assert');
|
||
const { render, plainText } = require('../../../app/lib/markdown');
|
||
|
||
describe('test/app/lib/markdown.test.js', () => {
|
||
it('标题 / 段落 / 行内样式 / 目录', () => {
|
||
const { html, toc } = render([
|
||
'# 一级标题',
|
||
'',
|
||
'这是 **粗体**、`代码` 和 [链接](https://example.com)。',
|
||
'',
|
||
'## 二级标题',
|
||
].join('\n'));
|
||
|
||
assert.ok(html.includes('<h1 id="sec-1">一级标题</h1>'));
|
||
assert.ok(html.includes('<strong>粗体</strong>'));
|
||
assert.ok(html.includes('<code>代码</code>'));
|
||
assert.ok(html.includes('target="_blank"'));
|
||
assert.ok(html.includes('<h2 id="sec-2">二级标题</h2>'));
|
||
assert.deepStrictEqual(toc.map(item => item.level), [ 1, 2 ]);
|
||
});
|
||
|
||
it('列表 / 引用 / 代码块', () => {
|
||
const { html } = render([
|
||
'- 一',
|
||
'- 二',
|
||
'',
|
||
'> 引用一行',
|
||
'',
|
||
'```js',
|
||
'console.log(1)',
|
||
'```',
|
||
].join('\n'));
|
||
|
||
assert.ok(html.includes('<ul><li>一</li><li>二</li></ul>'));
|
||
assert.ok(html.includes('<blockquote>'));
|
||
assert.ok(html.includes('class="language-js"'));
|
||
assert.ok(html.includes('console.log(1)'));
|
||
});
|
||
|
||
it('先转义再拼标签:脚本与 javascript: 链接不会漏出去', () => {
|
||
const html = render([
|
||
'<script>alert(1)</script>',
|
||
'',
|
||
'[点我](javascript:alert(1))',
|
||
'',
|
||
'',
|
||
].join('\n')).html;
|
||
|
||
assert.ok(!html.includes('<script>'), 'HTML 必须被转义');
|
||
assert.ok(html.includes('<script>'));
|
||
assert.ok(!html.includes('javascript:'), 'javascript: 协议必须被拒绝');
|
||
});
|
||
|
||
it('plainText:去掉记号并截断', () => {
|
||
assert.strictEqual(plainText('# 标题\n\n正文 `code`'), '标题 正文 code');
|
||
assert.ok(plainText('a'.repeat(200), 10).endsWith('…'));
|
||
});
|
||
});
|