~cytrogen/hexo-mastodon-syndicate

Hexo 项目用的 Mastodon 联合发布脚本。
b0f22fc2 — Cytrogen a month ago
初始提交:hexo-mastodon-syndicate

refs

main
browse  log 

clone

read-only
https://git.cytrogen.icu/~cytrogen/hexo-mastodon-syndicate
read/write
ssh://git@git.cytrogen.icu:22222/~cytrogen/hexo-mastodon-syndicate

You can also use your local clone with git send-email.

#hexo-mastodon-syndicate

#hexo-mastodon-syndicate

一个 Hexo 项目用的 Mastodon 联合发布脚本,实现 POSSE(Publish on your Own Site, Syndicate Elsewhere)工作流。

#工作流程

  1. 在文章的 front matter 中添加 syndicate: true
  2. 运行脚本,自动发送 Mastodon 帖子(包含标题、摘要和链接)
  3. 脚本将 syndicate: true 替换为 syndication: <Mastodon 帖子 URL>
  4. 提交修改后的文件并部署

#安装

#方式一:npm 安装

npm install --save-dev hexo-mastodon-syndicate

#方式二:直接复制

syndicate.js 复制到你的 Hexo 项目中即可使用。

#配置

#方式一:_config.yml

在 Hexo 的 _config.yml 中添加以下配置段:

diary_sources:
  mastodon:
    server: https://your.mastodon.instance
    access_token: your_access_token_here

脚本会自动读取 _config.yml 中的 url 字段作为博客地址。

#方式二:环境变量

设置以下环境变量即可,无需修改 _config.yml

环境变量说明必填
MASTODON_SERVERMastodon 实例地址
MASTODON_ACCESS_TOKENMastodon 访问令牌
SYNDICATE_SITE_URL博客站点 URL

环境变量也可以和 _config.yml 混合使用,环境变量的优先级更高。

#Mastodon 访问令牌

前往你的 Mastodon 实例的 设置 → 开发 → 新建应用,创建一个具有 write:statuses 权限的访问令牌。

#可选:Org 文件同步

如果你使用 Org-mode 写作,脚本可以同时更新对应的 .org 源文件,在其中添加 #+SYNDICATION: 属性。

设置 SYNDICATE_ORG_DIR 环境变量指向你的 Org 文件目录:

export SYNDICATE_ORG_DIR=~/Documents/Org/blog/posts

未设置此变量时,Org 文件同步功能自动跳过。

#可选:自定义文章目录

默认扫描 source/_posts 目录。如需更改:

export SYNDICATE_POSTS_DIR=source/_articles

#用法

在 Hexo 项目根目录运行:

# 通过 npx
npx hexo-mastodon-syndicate

# 或直接运行
node node_modules/hexo-mastodon-syndicate/syndicate.js

# 如果是直接复制的脚本
node syndicate.js

脚本只负责联合发布和更新文件,不会自动提交或推送。

#一键发布(syndicate commit push)

如果你的项目通过 git push 自动触发部署(如 VPS 上的 Git hook、GitHub Pages、Netlify 等),可以使用 hexo-mastodon-publish 一键完成整个流程:

npx hexo-mastodon-publish

它的完整流程:

  1. 检查工作区是否干净(有未提交的改动会报错退出)
  2. 运行联合发布
  3. 自动 git commit 修改后的文件
  4. git push 到当前分支的上游远程

#文章示例

---
title: 我的新文章
date: 2026-01-01 12:00:00
syndicate: true
abbrlink: abc123
---

运行脚本后,syndicate: true 会被替换为:

syndication: https://your.instance/@you/123456789

#许可证

MIT