diff --git a/README.md b/README.md index 01e57c56..5ddf55aa 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,12 @@ BASE_PATH=/MyBlogDoc/ pnpm preview 离线搜索在页面加载后利用空闲时间自动准备完整索引与所需静态资源,不显示下载按钮。后台任务使用低优先级请求,搜索输入、隐藏标签页、节省流量和慢速网络会让任务延后。准备完成后,可以断网搜索新关键词、筛选和分页;已访问的文章可离线阅读。后台更新失败保留原完整缓存,缓存只属于当前博客路径。[方案比较、构建与验收说明](docs/offline-search.md)。 +## 公众号与文章评论 + +中文界面的首页、文章末尾和联系页提供「泯泷ML」公众号关注卡;社交栏、页脚和手机菜单提供入口。二维码使用原图,支持微信扫码、保存图片和复制公众号名称。公众号名称与图片路径统一维护在 `src/config/site.ts`。 + +公开且非空的文章使用 [Giscus](https://giscus.app/) 接入本仓库的 GitHub Discussions,访客使用 GitHub 登录留言,无需配置 Token。中英文界面按文章源路径共享讨论,评论区按需加载并跟随明暗主题;评论服务失败时可以重试或前往 GitHub 交流。[配置和映射说明](docs/comments.md)。 + ## SEO 与 GEO 站点输出 Blog、Person、BlogPosting 和可见面包屑对应的 JSON-LD,补齐 OG/Twitter 分享图、可信发布时间与更新时间、原文作者与来源信息,以及 sitemap 的 lastmod。未知的发布时间不会用构建时间补造。英文界面共享原文,因此文章语言标注遵循正文语言。 diff --git a/docs/comments.md b/docs/comments.md new file mode 100644 index 00000000..6fe1d54d --- /dev/null +++ b/docs/comments.md @@ -0,0 +1,25 @@ +# GitHub Discussions 评论 + +文章评论使用 [Giscus](https://giscus.app/),数据保存在公开仓库 `MoMeak9/MyBlogDoc` 的 GitHub Discussions 中。访客通过 GitHub 登录留言,不需要在博客中配置 GitHub Token。 + +## 启用 + +1. 在仓库 **Settings → General → Features** 开启 **Discussions**。 +2. 安装 [Giscus GitHub App](https://github.com/apps/giscus),允许它访问 `MyBlogDoc`。 +3. 选择 **Announcements** 类型的讨论分类,并将真实的分类名和 GraphQL 分类 ID 写入 `src/config/site.ts` 的 `comments` 配置。仓库 ID 已填入真实值;分类 ID 为空时保留 GitHub 交流入口,不请求 Giscus。 + +读取仓库与分类 ID: + +```sh +gh api graphql -f query='query { repository(owner:"MoMeak9", name:"MyBlogDoc") { id discussionCategories(first:25) { nodes { id name slug } } } }' +``` + +启用后运行 `pnpm check`、`pnpm build`、`pnpm test:build`,将构建部署到站点。浏览器需要访问 `giscus.app`,登录需要 GitHub;博客本身没有评论服务器。 + +## 映射与行为 + +- 只在公开且非空的文章页面显示评论,位置在正文和公众号关注卡之后,不进入文章搜索索引。 +- 使用 `specific` 映射,讨论标识为 Markdown 文章的 `post.id`;中英文界面、项目部署前缀与自定义域名共享同一讨论。修改文章标题不会改变讨论;移动文章源文件会改变标识,需要单独迁移已有讨论。 +- `strict` 开启,避免相似文章名匹配到其他讨论。尚无评论时的 `Discussion not found` 是正常状态,首次留言或表情会由 Giscus 创建讨论。 +- 接近评论区时才加载;明暗主题切换时同步 iframe。加载失败提供重试与 GitHub 交流入口,收到当前 iframe 的讨论元数据后将入口指向对应线程。 +- GitHub App 安装状态不能仅凭博客构建判断;需在部署后的页面核验评论显示与 GitHub 登录,且不要把未实际提交的评论描述为已验证。 diff --git a/public/images/wechat-ml-qr.jpg b/public/images/wechat-ml-qr.jpg new file mode 100644 index 00000000..e17876c8 Binary files /dev/null and b/public/images/wechat-ml-qr.jpg differ diff --git a/src/components/ArticlePage.astro b/src/components/ArticlePage.astro index eb4e6ef6..bf8568e2 100644 --- a/src/components/ArticlePage.astro +++ b/src/components/ArticlePage.astro @@ -3,6 +3,8 @@ import BaseLayout from "../layouts/BaseLayout.astro"; import PostCard from "./PostCard.astro"; import Icon from "./Icon.astro"; import Diagrams from "./Diagrams.astro"; +import WeChatFollow from "./WeChatFollow.astro"; +import Comments from "./Comments.astro"; import { ui, dateLabel, type Locale } from "../i18n"; import { getPosts, renderPost, type Post } from "../lib/content"; import { localePath, normalizeBase, postPath } from "../lib/paths.mjs"; @@ -163,6 +165,8 @@ const editUrl = `https://github.com/MoMeak9/MyBlogDoc/edit/main/src/${post.id.sp )} + {locale === "zh" && } + {post.indexable && !post.empty && } {toc.length > 0 && (