Mastodon Integration

(RSS->Mastodon)->Webmention->Share

思路

为每一篇博文生成一个对应的Toot,并把Toot链接回链到博文上,形成双向链接,以Toot接入Fediverse;
前者有web规范,以前有linkback,pingback等,这里用Indiweb推荐的Webmention形式

步骤

  1. 用hexo生成atom.xml文件,即Blog文章的订阅源

  2. 用Huginn/IFTTT/自定义bot订阅1的RSS源,对每一条目调用Mastodon API, POST Statuses,content为我发布了博客文章: {title} {url}

  3. 取2的response body,解析为JSON对象,取其id,即为toot的id

  4. 调用telegraph API, source为3中返回的id拼装出的url https://{mastodonDomain}/interact/{statusId}?type=reply,target为RSS每个条目的url

    • telegraph会把这个消息发送给对应的webmention server
  5. 在Blog模板添加“分享”脚本,调用webmention API,获取页面收到的webmention

  6. 过滤5中获取的webmention,过滤出由自己mastodon实例发出的webmention(根据域名和作者)
    6-1. 取webmention的url,即第4步拼装出的url,把url设置到【回复】链接上;
    6-2. 把type=reply替换成type=reblog,把url设置到【转嘟】链接上
    6-3. 把type=reply替换成type=favourite,设置到【喜欢】链接上