refactor: posts/show.html 内联 JS 拆分为独立文件

- 拆分 926 行内联 JS 为 5 个独立模块文件
- post-view.js: Vditor 渲染 + 提交审核按钮 (~50 行)
- post-energize.js: 赋能按钮 + 弹窗 (~76 行)
- post-reactions.js: 赞/踩系统 (~71 行)
- post-favorite.js: 收藏按钮 + 收藏夹弹窗 (~218 行)
- post-comments.js: 评论系统 (~456 行)
- show.html 从 1080 行缩减至 159 行
This commit is contained in:
2026-06-02 20:00:06 +08:00
parent a8a52f5fd0
commit 2e6e7fc057
6 changed files with 874 additions and 926 deletions

View File

@ -0,0 +1,48 @@
// Vditor Markdown 渲染 + 外部链接处理 + 提交审核按钮
(function() {
// ====== Vditor 渲染 ======
var el = document.getElementById('postContent');
var mdEl = document.getElementById('postMdContent');
if (el && mdEl) {
var md = mdEl.value;
Vditor.preview(el, md, {
cdn: '/static/vditor',
theme: { current: 'light', path: '/static/vditor/dist/css/content-theme' },
hljs: { style: 'github-dark', enable: true },
after: function() {
var host = window.location.host;
var links = el.querySelectorAll('a[href^="http"]');
for (var i = 0; i < links.length; i++) {
var a = links[i];
if (a.host && a.host !== host) {
a.setAttribute('rel', 'nofollow noopener noreferrer');
a.setAttribute('target', '_blank');
}
}
}
});
// shortcode 占位 div 替换为对应卡片 UI
renderShortcodes(el);
}
// ====== 提交审核按钮 ======
var submitBtn = document.getElementById('submitAuditBtn');
if (submitBtn) {
submitBtn.addEventListener('click', function() {
if (!confirm('确认提交审核?审核通过后将公开发布。')) return;
fetch('/api/posts/' + submitBtn.dataset.id + '/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': getCSRFToken()
}
})
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.success) { window.location.reload(); }
else { alert(d.message || '提交失败'); }
})
.catch(function() { alert('请求失败'); });
});
}
})();