优化评论逻辑

This commit is contained in:
Han 2025-03-03 17:16:54 +08:00
parent b0e52ef29d
commit f116d9feb2
4 changed files with 25 additions and 7 deletions

View File

@ -1,11 +1,22 @@
import { LoadScript } from "../utils/index";
import SITE_INFO from "../config";
// 图片灯箱
import "../../public/assets/js/view-image.min.js";
declare const ViewImage: any;
import { LoadScript } from "../utils/index";
declare const twikoo: any;
// 处理评论区数据
const formateComment = () => {
// 图片灯箱
ViewImage && ViewImage.init(".vh-comment img:not(.tk-avatar-img)");
// 处理 URL
document.querySelectorAll('.vh-comment a[href="#"]').forEach(link => link.removeAttribute('href'));
}
// 初始化评论插件
export default async () => {
const commentDOM = '.vh-comment>section'
if (!document.querySelector(commentDOM) || !SITE_INFO.Twikoo.envId) return;
document.querySelector(commentDOM)!.innerHTML = '<section></section>'
await LoadScript("https://registry.npmmirror.com/twikoo/1.6.41/files/dist/twikoo.all.min.js");
twikoo.init({ envId: SITE_INFO.Twikoo.envId, el: commentDOM })
twikoo.init({ envId: SITE_INFO.Twikoo.envId, el: commentDOM, onCommentLoaded: () => setTimeout(formateComment) })
}

View File

@ -1,4 +1,3 @@
// 图片懒加载
import LazyLoad from "vanilla-lazyload";

View File

@ -180,8 +180,8 @@ section.vh-container {
// p标签样式
// ul标签样式
p,
ul:not(.vh-vhMusic ul),
ol:not(.vh-vhMusic ol) {
ul:not(.vh-vhMusic ul, .vh-comment ul),
ol:not(.vh-vhMusic ol, .vh-comment ol) {
margin: 0;
padding: 0.618rem 0;
font-size: 0.9375rem;
@ -211,8 +211,8 @@ section.vh-container {
}
}
ul:not(.vh-vhMusic ul),
ol:not(.vh-vhMusic ol) {
ul:not(.vh-vhMusic ul, .vh-comment ul),
ol:not(.vh-vhMusic ol, .vh-comment ol) {
box-sizing: border-box;
padding-left: 1.25rem;
display: flex;

View File

@ -12,6 +12,14 @@
.twikoo {
font-size: 0.88rem;
img:not(.tk-avatar-img) {
cursor: pointer;
}
a {
cursor: pointer;
}
&:not(.tk-admin-container) {
// p标签样式