refactor(widget): 简化前端配置并重构核心逻辑
移除前端配置中的 postSlug 和 avatarPrefix 参数,改为从后端接口获取 重构 CWDComments 核心类,自动推导 postSlug 等参数并异步加载服务端配置 更新文档和示例页面以反映配置变更
This commit is contained in:
38
docs/.vitepress/components/footerDoc.vue
Normal file
38
docs/.vitepress/components/footerDoc.vue
Normal file
@@ -0,0 +1,38 @@
|
||||
<template>
|
||||
<div id="zcomments" ref="commentsRoot"></div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
const commentsRoot = ref(null);
|
||||
|
||||
onMounted(async () => {
|
||||
if (!commentsRoot.value || typeof window === "undefined") return;
|
||||
|
||||
const apiBaseUrl = "https://cwd-comments-api.anghunk.workers.dev";
|
||||
|
||||
if (!apiBaseUrl) return;
|
||||
|
||||
if (!window.CWDComments) {
|
||||
await new Promise((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = "https://cwd-comments.zishu.me/cwd-comments.js";
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = (e) => reject(e);
|
||||
document.head.appendChild(script);
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
if (!window.CWDComments) return;
|
||||
|
||||
const comments = new window.CWDComments({
|
||||
el: commentsRoot.value,
|
||||
apiBaseUrl,
|
||||
postSlug: window.location.pathname,
|
||||
});
|
||||
|
||||
comments.mount();
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user