feat: Tiptap替换为Vditor + MD存储重构 + Shortcode卡片扩展

- 编辑器:Tiptap 替换为 Vditor 3.11.2(wysiwyg 模式,本地托管 5.8MB,去 CDN)
- 存储:Body 字段从 HTML 改为 Markdown,去除 BodyHTML,新增 Excerpt 列表摘要
- 安全:去除 bluemonday 依赖(MD 纯文本无 XSS 风险),go.mod 已清理
- Shortcode:新增 [zone:type:params] 扩展语法,支持活动/游戏/投票/资源卡片
- 图片上传:POST /api/posts/upload-image 直接返回 Vditor 原生响应格式
- 草稿:localStorage 键名改为 draft_post_body_md,与旧 HTML 草稿隔离
- 详情页:Vditor.method.min.js 客户端 MD → HTML 渲染,去 highlight.js CDN
- 样式:去 Tiptap 样式 ~190 行,精简工具栏 CSS,新增卡片样式
- 文档:vditor-migration-plan.md 完整记录迁移决策、架构、用法
This commit is contained in:
2026-05-30 15:56:22 +08:00
parent c9808ab9b2
commit 6ec12010f3
121 changed files with 8267 additions and 613 deletions

View File

@ -125,7 +125,7 @@
color: #2980b9;
}
/* 代码块基础样式(背景色与 github-dark 主题保持一致) */
/* 代码块基础样式 */
.post-detail-body pre {
position: relative;
background: #0d1117;
@ -138,23 +138,6 @@
font-family: 'Menlo', 'Consolas', 'Monaco', 'Liberation Mono', monospace;
}
/* 代码块语言标签JS 动态注入) */
.post-detail-body pre .code-lang-label {
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 4px 16px;
font-size: 11px;
font-weight: 600;
color: #8b949e;
background: #161b22;
border-radius: 8px 8px 0 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
pointer-events: none;
z-index: 1;
}
.post-detail-body pre code {
background: transparent !important;
border: none !important;
@ -171,8 +154,6 @@
font-size: 0.9em;
}
/* 代码块语法高亮由 highlight.js CDN 主题提供,此处仅保留基础布局 */
.post-detail-body img {
max-width: 100%;
height: auto;
@ -385,166 +366,148 @@
background: #fff;
}
/* ========== Tiptap 编辑器容器 ========== */
#editor-container {
/* ========== Vditor 编辑器容器 ========== */
/* Vditor 自动生成工具栏、编辑区、状态栏,仅做外层布局微调 */
#vditor {
flex: 1;
overflow: hidden;
min-height: 0;
background: #fff;
display: flex;
flex-direction: column;
}
.tiptap {
padding: 16px 24px;
outline: none;
min-height: 100%;
/* Vditor 工具栏微调 — 匹配项目主题色 */
.vditor-toolbar {
background: #fafafa !important;
border-bottom: 1px solid #e5e7eb !important;
}
/* Vditor 内容区适配 */
.vditor-content {
font-size: 15px;
line-height: 1.7;
color: #24292f;
}
.tiptap p { margin: 0.5em 0; }
.tiptap h1 { margin: 1em 0 0.5em; font-size: 2em; font-weight: 700; }
.tiptap h2 { margin: 0.8em 0 0.4em; font-size: 1.5em; font-weight: 700; }
.tiptap h3 { margin: 0.6em 0 0.3em; font-size: 1.17em; font-weight: 700; }
.tiptap ul, .tiptap ol { padding-left: 1.5em; margin: 0.5em 0; }
.tiptap li { margin: 0.2em 0; }
.tiptap ul[data-type="taskList"] { list-style: none; padding-left: 0; }
.tiptap ul[data-type="taskList"] li { display: flex; align-items: flex-start; gap: 0.4em; }
.tiptap ul[data-type="taskList"] li > label { flex-shrink: 0; margin-top: 0.15em; }
.tiptap blockquote {
border-left: 3px solid #3498db;
padding-left: 1em;
margin: 0.5em 0;
color: #6b7280;
/* Vditor 预览/渲染区域 — 详情页 */
.post-detail-body .vditor-reset {
font-size: 16px;
line-height: 1.8;
color: #1f2937;
}
.tiptap pre {
background: #1a2332;
color: #e2e8f0;
padding: 12px 16px;
border-radius: 6px;
/* Vditor 图片上传进度条 */
.vditor-upload {
position: fixed;
top: 0;
left: 0;
z-index: 10000;
}
/* ========== Shortcode 卡片通用 ========== */
/* 所有 shortcode 卡片共享的基础外观 */
.zone-card {
display: block;
margin: 16px 0;
}
.zone-card-loading {
display: block;
padding: 16px;
text-align: center;
color: #9ca3af;
font-size: 13px;
line-height: 1.5;
overflow-x: auto;
margin: 0.5em 0;
position: relative;
}
.tiptap pre code { background: transparent; padding: 0; color: inherit; font-size: inherit; white-space: pre; display: block; }
.tiptap code {
background: #f3f4f6;
padding: 2px 5px;
border-radius: 4px;
font-size: 0.9em;
font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
background: #f9fafb;
border: 1px dashed #d1d5db;
border-radius: 8px;
}
.tiptap pre .code-lang-label {
position: absolute;
top: 0; left: 0; right: 0;
padding: 4px 16px;
font-size: 11px;
font-weight: 600;
color: #94a3b8;
background: #2c3e50;
border-radius: 6px 6px 0 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
pointer-events: none;
z-index: 1;
}
/* highlight.js One Dark 语法高亮 — 编辑器内 */
.tiptap pre code .hljs-keyword,
.tiptap pre code .hljs-selector-tag,
.tiptap pre code .hljs-literal,
.tiptap pre code .hljs-section,
.tiptap pre code .hljs-link { color: #c792ea; }
.tiptap pre code .hljs-string,
.tiptap pre code .hljs-title,
.tiptap pre code .hljs-name,
.tiptap pre code .hljs-type,
.tiptap pre code .hljs-attribute,
.tiptap pre code .hljs-symbol,
.tiptap pre code .hljs-bullet,
.tiptap pre code .hljs-addition,
.tiptap pre code .hljs-variable,
.tiptap pre code .hljs-template-tag,
.tiptap pre code .hljs-template-variable { color: #c3e88d; }
.tiptap pre code .hljs-comment,
.tiptap pre code .hljs-quote,
.tiptap pre code .hljs-deletion,
.tiptap pre code .hljs-meta { color: #676e95; }
.tiptap pre code .hljs-number,
.tiptap pre code .hljs-regexp,
.tiptap pre code .hljs-built_in { color: #f78c6c; }
.tiptap pre code .hljs-function .hljs-title,
.tiptap pre code .hljs-doctag,
.tiptap pre code .hljs-formula { color: #82aaff; }
.tiptap pre code .hljs-tag,
.tiptap pre code .hljs-subst { color: #f07178; }
.tiptap pre code .hljs-emphasis { font-style: italic; }
.tiptap pre code .hljs-strong { font-weight: bold; }
.tiptap pre code .hljs-attr,
.tiptap pre code .hljs-selector-attr,
.tiptap pre code .hljs-selector-class,
.tiptap pre code .hljs-selector-id,
.tiptap pre code .hljs-selector-pseudo { color: #ffcb6b; }
.tiptap hr { border: none; border-top: 1px solid #e5e7eb; margin: 1em 0; }
.tiptap img { max-width: 100%; height: auto; border-radius: 6px; }
.tiptap a { color: #3498db; text-decoration: underline; }
.tiptap p.is-editor-empty:first-child::before {
content: attr(data-placeholder);
float: left;
color: #c4c4c4;
pointer-events: none;
height: 0;
}
/* ========== 工具栏 ========== */
.editor-toolbar {
/* 通用卡片布局 */
.zone-card-event,
.zone-card-game,
.zone-card-poll,
.zone-card-resource {
display: flex;
gap: 2px;
padding: 6px 12px;
align-items: center;
gap: 14px;
padding: 16px 18px;
margin: 14px 0;
border-radius: 10px;
border: 1px solid #e5e7eb;
background: #fafafa;
border-bottom: 1px solid #e5e7eb;
flex-shrink: 0;
flex-wrap: wrap;
transition: box-shadow 0.2s;
}
.editor-toolbar button {
display: inline-flex;
.zone-card-event:hover,
.zone-card-game:hover,
.zone-card-poll:hover,
.zone-card-resource:hover {
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.zone-card-event-icon,
.zone-card-game-icon,
.zone-card-poll-icon,
.zone-card-resource-icon {
font-size: 28px;
flex-shrink: 0;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 30px;
border: 1px solid transparent;
border-radius: 4px;
background: transparent;
color: #374151;
font-size: 13px;
cursor: pointer;
transition: background 0.15s;
border-radius: 8px;
background: #f3f4f6;
}
.editor-toolbar button:hover { background: #e5e7eb; }
.editor-toolbar button.is-active { background: #1a2332; color: #fff; }
.code-lang-select {
height: 30px;
padding: 0 6px;
border: 1px solid transparent;
border-radius: 4px;
background: transparent;
color: #374151;
.zone-card-event-body,
.zone-card-game-body,
.zone-card-poll-body,
.zone-card-resource-body {
flex: 1;
min-width: 0;
}
.zone-card-event-title,
.zone-card-game-title,
.zone-card-poll-title,
.zone-card-resource-title {
font-size: 14px;
font-weight: 600;
color: #111827;
}
.zone-card-event-id,
.zone-card-game-slug,
.zone-card-poll-id,
.zone-card-resource-id {
font-size: 12px;
cursor: pointer;
font-family: inherit;
outline: none;
color: #9ca3af;
margin-top: 2px;
font-family: 'Menlo', 'Consolas', monospace;
}
.code-lang-select:hover { border-color: #e5e7eb; }
.code-lang-select:focus { border-color: #3498db; }
.editor-toolbar .toolbar-divider {
width: 1px;
background: #e5e7eb;
margin: 3px 4px;
.zone-card-event-link,
.zone-card-game-link,
.zone-card-resource-link {
font-size: 13px;
color: #6366f1;
text-decoration: none;
font-weight: 500;
white-space: nowrap;
}
.zone-card-event-link:hover,
.zone-card-game-link:hover,
.zone-card-resource-link:hover {
color: #4f46e5;
}
/* 投票 — 预留状态 */
.zone-card-poll-pending {
font-size: 12px;
color: #d97706;
background: #fef3c7;
padding: 4px 10px;
border-radius: 12px;
white-space: nowrap;
}