跳转到内容

评论系统配置

ShokaX 内置了 Waline 评论系统的支持,只需简单配置即可为博客添加评论功能。

Waline 是一款基于 LeanCloud / Vercel / CloudBase 的轻量评论系统。你需要先部署 Waline 服务端。

参考 Waline 官方文档 完成服务端部署,获取一个类似 https://comments.example.com 的服务地址。

src/theme.config.ts 中启用评论并填入你的 Waline 服务地址:

src/theme.config.ts
export default defineConfig({
comments: {
enable: true,
waline: {
serverURL: "https://comments.example.com",
},
},
});

配置完成后,每篇文章底部会自动显示评论区。

lang 用于指定评论界面的显示语言:

src/theme.config.ts
export default defineConfig({
comments: {
enable: true,
waline: {
serverURL: "https://comments.example.com",
lang: "zh-CN", // 中文界面
},
},
});

Waline 支持自动跟随网站的暗黑模式:

src/theme.config.ts
export default defineConfig({
comments: {
enable: true,
waline: {
serverURL: "https://comments.example.com",
dark: "auto", // 自动跟随系统
},
},
});

dark 支持的取值:

说明
false始终使用亮色模式
true始终使用暗色模式
"auto"自动跟随系统偏好

默认情况下,Waline 使用当前页面路径作为评论标识。如果遇到多语言或 URL 尾斜杠等场景需要统一路径,可以手动指定:

src/theme.config.ts
export default defineConfig({
comments: {
enable: true,
waline: {
serverURL: "https://comments.example.com",
path: "/posts/my-article", // 自定义评论路径
},
},
});

开启评论后,你还可以在页脚启用「最新评论」小部件:

src/theme.config.ts
export default defineConfig({
widgets: {
recentComments: true,
recentCommentsLimit: 5, // 最多显示 5 条
},
});

如果暂时不需要评论功能,设置 enable: false 即可:

src/theme.config.ts
export default defineConfig({
comments: {
enable: false,
},
});
字段类型默认值说明
comments.enablebooleanfalse是否启用评论系统
comments.waline.serverURLstring""Waline 服务端地址
comments.waline.langstring评论界面语言(如 "zh-CN"
comments.waline.darkboolean ` string`
comments.waline.pathstring自定义评论路径(可选)
src/theme.config.ts
export default defineConfig({
siteName: "我的博客",
comments: {
enable: true,
waline: {
serverURL: "https://comments.example.com",
lang: "zh-CN",
dark: "auto",
},
},
widgets: {
recentComments: true,
recentCommentsLimit: 10,
},
});

推荐使用 Vercel 免费部署,参考 Waline 文档 - Vercel 部署。部署完成后会得到一个类似 https://your-waline.vercel.app 的地址。

Waline 支持多种后端,包括 LeanCloud、CloudBase、MySQL 等。建议新手使用 LeanCloud 国际版(免费额度充足)。

Q: 可以不使用 Waline 换其他评论系统吗?

Section titled “Q: 可以不使用 Waline 换其他评论系统吗?”

ShokaX 目前仅内置了 Waline 支持。如果想使用其他评论系统(如 Giscus、Twikoo),需要自行修改 src/components/post/WalineComments.svelte

津 ICP 备2022001375 号
津公网安备 12011402001353 号