Astro 博客迁移与评论系统汇总

Feb 13, 2026 | 8 min

目标与范围

  • 从 Hugo + Docsy 迁移到 Astro(EdgeOne Pages)。
  • 保留中文博客内容,按新 URL 方案输出到 /posts 体系。
  • 评论系统使用 Edge Functions + KV,支持审核、回复通知、反垃圾与站长标识。

路由与重定向

  • 统一首页和多语言入口到新路径(见 public/_redirects)。
  • 已保留常用旧链接 301 到新页面(见 public/_redirects)。

内容迁移

  • 迁移中文博客文章到 src/content/posts/
  • 合并特殊文章:D:\EdgeOne\fungit.org-edgefunctions\fungit.org-blog-hugo-main\content\zh\docs\Hugo 下两篇合并为一篇(已落入新文章集合)。

主题与前端样式

  • 文章与列表页样式统一为 Astro 主题风格。
  • 首页/列表封面随机池:public/covers/default/
  • 背景封面池:public/covers/full/
  • 随机封面逻辑:src/lib/covers.ts + src/layouts/ThemeLayout.astro
  • 文章详情独立样式:public/styles/post-detail.css(避免 global.css 过大)。

评论系统(Edge Functions)

API

  • POST /api/comments:提交评论(进入 pending)。
  • GET /api/comments:读取已审核评论(分页)。
  • 管理端:
    • POST /api/admin/comments/approve
    • POST /api/admin/comments/reject
    • GET /api/admin/comments/pending
    • GET /api/admin/comments/paths
    • GET/POST /api/admin/comments/allowed-paths
    • POST /api/admin/comments/author-token

字段与功能

  • 必填:nicknameemailcontent
  • 可选:websiteUrlnotifyReplies
  • 防垃圾:honeypot(websiteHp)、URL/关键词/重复提交/频率限制。
  • 回复通知:父评论可关闭通知;自回复不发送邮件。
  • 评论者网站链接展示(昵称可点击)。
  • 评论基础信息缓存(浏览器):fungit.comment.profile.v1
  • 站长标识:isAuthor,前端展示“站长”徽章 + 高亮昵称样式。

站长作者 Token

  • 后台生成短期 token(/api/admin/comments/author-token),自动写入:
    • fungit.comment.author_token.v1(作者身份)
    • fungit.comment.profile.v1(昵称/邮箱/网站)
  • Token 验签后写入 isAuthor=true,历史评论保持标记。

邮件通知(Gmail API)

  • 评论回复通知模板已接入。
  • 关键变量见 .env.example
    • MAIL_*GMAIL_*

广告与统计

  • 广告位(可选):
    • 首页列表、文章正文、评论区(见 .env.example
  • 统计:
    • Google Analytics、Microsoft Clarity、Cloudflare Web Analytics(见 .env.example

EdgeOne Headers

  • public/edgeone.json 增加响应头:
    • Server: Fungit
    • /_astro/* 静态资源缓存优化

头像与站长头像

  • 普通评论头像:随机池 public/avatars/
  • 站长头像:PUBLIC_AUTHOR_AVATAR_URL(默认 /avatars/author.png)。

关键配置(.env.example

  • 站长 token:
    • AUTHOR_TOKEN_SECRET
    • AUTHOR_TOKEN_TTL_SECONDS
    • AUTHOR_DEFAULT_NICKNAME
    • AUTHOR_DEFAULT_WEBSITE_URL
  • 站长头像:
    • PUBLIC_AUTHOR_AVATAR_URL

现状与建议

  • 主线功能已完成:迁移、评论、通知、广告、统计、重定向。
  • 如需新增:
    • 增强作者 UI 动效
    • 评论后台增加站长模式可视状态提示
    • 站长头像进一步“二次元风”定制

Comments

Email is only used for reply notifications and is never shown publicly.