diff --git a/src/content/posts/fuwari-add-twikoo.md b/src/content/posts/fuwari-add-twikoo.md new file mode 100644 index 0000000..52ffb4c --- /dev/null +++ b/src/content/posts/fuwari-add-twikoo.md @@ -0,0 +1,128 @@ +--- +title: 给你的fuwari添加twikoo评论系统 +published: 2025-10-10 +description: 本文讲述了如何给你的fuwari添加twikoo评论系统。 +tags: + - fuwari + - twikoo +category: 教程 +draft: false +lang: zh_CN +--- + +# 给你的fuwari添加twikoo评论系统 + twikoo是一个优秀的评论系统,有美观的界面,而且可以高度自定义。(最重要的是可以匿名发评论) + # 部署twikoo + 先访问[twikoo的官网](https://twikoo.js.org/)点击`快速上手`,会跳转到Twikoo 文档,再点击`云函数部署`选择一个你喜欢的部署方式。 +## MongoDB Atlas 注册 +我比较喜欢Netlify部署,因为我已经有Netlify账号了,大部分的部署方式都是要MongoDB的数据库的,Netlify部署就需要。MongoDB Atlas为免费账户可以永久使用 500 MiB 的数据库,足够存储 Twikoo 评论使用。[注册MongoDB Atlas的教程](https://twikoo.js.org/mongodb-atlas.html)Twikoo 文档中有详细的教程。 +## Netlify 部署 +获取到 MongoDB 连接字符串后要妥善保管(这个字符串可以连接数据库)[Netlify 部署教程](https://twikoo.js.org/backend.html#netlify-%E9%83%A8%E7%BD%B2) +# 前端部署 +在拿到环境 id后就可以开始在fuwari中部署了。 +下载[https://github.com/saicaca/fuwari/tree/comments](https://github.com/saicaca/fuwari/tree/comments)中的/src/components/comment(把整个文件夹下载下来),把comment文件夹复制到你的fuwari的/src/components中,删掉`Giscus.astr`和`Disqus.astro` +把`index.astro`中的代码全部替换 +``` +--- +import type { CollectionEntry } from 'astro:content' +import { commentConfig } from '@/config' +import Twikoo from './Twikoo.astro' +interface Props { + post: CollectionEntry<'posts'> +} + +const { id, data, slug } = Astro.props.post + +const path = `/posts/${slug}` +const url = `${Astro.site?.href}${path}` + +let commentService = '' +if (commentConfig?.twikoo) { + commentService = 'twikoo' +} +--- +