lesspub
lesspub copied to clipboard
Serverless ActivityPub for static blogs
trafficstars
LessPub
A serverless ActivityPub implementation.
Supported Activities and Objects:
- Send your blog post as Create-Note (toot).
- Receive Follow.
- Receive Undo-Follow.
- Receive Like.
- Receive Undo-Like.
- Receive Announce (boost).
- Receive Undo-Announce (currently Mastodon only send Undo-Announce to followers, while Firefish can send that to you).
- Receive Create-Note as reply to your blog posts.
- Receive Delete-Note to delete a reply.
Basically, this implementation allows Mastodon users search, follow, like, reply your blog in Mastodon.
The saved files are stored in your GitHub repo as plain json. You can load it using your favoriate static blog generator to display them.
Environmental variables
| Name | Value | Example |
|---|---|---|
| AP_BASE_URL | Your blog URL | https://example.com |
| AP_PRIVATE_KEY | RSA private key in one line | -----BEGIN PRIVATE KEY-----\n……\n-----END PRIVATE KEY----- |
| AP_GH_TOKEN | GitHub token that has read & write access to your blog repo | github_…… |
| AP_GH_BASE_URL | The repo contents API path to store your follower, likes and replies | https://api.github.com/repos/YOUR_USER_NAME/YOUR_REPO_NAME/contents/YOUR_FOLDER |
| AP_EXTRA_INBOXES | (Optional) Extra inboxes’ URLs you want to deliver, separated by comma | https://RELAY1/inbox,https://RELAY2/inbox |
The private and public key can be generated by:
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
Host on Netlify
- Set the above environmental variables in your Netlify settings.
- Add this repo as a submodule.
cd $BLOG_BASE_DIRECTORY mkdir -p netlify/functions git submodule add https://github.com/sinofp/lesspub.git netlify/functions/lesspub - Copy/merge
netlify.toml,package.jsonto$BLOG_BASE_DIRECTORY. - Copy
webfingerto$BLOG_STATIC_DIRECTORY/.well-known/webfingerand edit it with your blog details. - Copy
actor.jsonto$BLOG_BASE_DIRECTORY/actor.jsonand edit it with your blog details. - Run
atom2activity.shto generateNote Object,Create Activity,Outbox(You may need to modify the paths in the script). - Run
node netlify/functions/lesspub/Send.jsto send the latestCreate ActivityfromOutbox.
You can put the last two steps into your build command to let Netlify run it for you.
It should be easy to port to Vercel/CloudFlare.
Load and display likes/replies using static blog generators
Showing who liked your post using Zola:
{% set likes = "static/likes/" ~ page.slug %}
{% set collection = load_data(path=likes, format="json", required=false) %}
{% if collection %}
<br />
<details open>
<summary>{{ collection.totalItems }} likes:</summary>
<ol reversed>
{% for actor in collection.orderedItems %}
{% set actor_json = load_data(url=actor, format="json", headers=["accept=application/activity+json"]) %}
<li><a href="{{ actor }}">{{ actor_json.name }}</a></li>
{% endfor %}
</ol>
</details>
{% endif %}