Skip to content

sinofp/lesspub

Repository files navigation

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

  1. Set the above environmental variables in your Netlify settings.
  2. 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
  3. Copy/merge netlify.toml, package.json to $BLOG_BASE_DIRECTORY.
  4. Copy webfinger to $BLOG_STATIC_DIRECTORY/.well-known/webfinger and edit it with your blog details.
  5. Copy actor.json to $BLOG_BASE_DIRECTORY/actor.json and edit it with your blog details.
  6. Run atom2activity.sh to generate Note Object, Create Activity, Outbox (You may need to modify the paths in the script).
  7. Run node netlify/functions/lesspub/Send.js to send the latest Create Activity from Outbox.

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 %}