medienbaecker / kirby-mastodon
Two-way Mastodon integration for Kirby: post pages from the Panel or CLI, fetch and display replies
Package info
github.com/medienbaecker/kirby-mastodon
Type:kirby-plugin
pkg:composer/medienbaecker/kirby-mastodon
Requires
README
Post Kirby pages to Mastodon from the Panel or CLI. Display replies, stars and boosts on the backend and frontend.
Installation
composer require medienbaecker/kirby-mastodon
Configuration
// site/config/config.php return [ 'medienbaecker.kirby-mastodon' => [ 'instance' => 'https://mastodon.social', 'token' => 'YOUR_APP_TOKEN_HERE', // scope: write:statuses 'post.default' => '{{ page.title }}: {{ page.url }}', ], ];
All options:
| Option | Default | |
|---|---|---|
instance |
Mastodon instance URL | |
token |
App token with write:statuses scope |
|
post.default |
{{ page.title }}\n\n{{ page.url }} |
Default toot text. String or closure receiving the page. Supports page/site query placeholders. The kirby and user globals are intentionally shadowed so user-edited templates can't leak {{ kirby.option('token') }} or similar. |
name |
Mastodon |
Brand name shown in the section labels |
field |
mastodon_url |
Page field that stores the posted toot URL |
cache.ttl |
5 |
Reply cache freshness in minutes. 0 disables. |
Posting
Add the section to a page blueprint:
sections: mastodon: type: mastodon
Before posting the section shows a textarea seeded with post.default, a Preview toggle, and a Post button. After posting it shows reply, boost and favourite counts plus Refresh and Unlink buttons. The { } button opens a dialog listing every supported placeholder. Only the posted URL is stored on the page (in mastodon_url); the toot text itself lives on Mastodon. Unlinking only clears the local field; the toot is left intact.
Or post from the CLI:
kirby mastodon:post path/to/article
kirby mastodon:post path/to/article --text="Custom toot for {{ page.title }}"
Requires composer global require getkirby/cli.
Displaying replies
<?php snippet('mastodon-replies') ?>
The wrapper snippet pulls in sub-snippets for heading, stats, list, reply, outro, empty, and error. Override any of them by placing your own version at site/snippets/mastodon-replies/<name>.php.
Reply data is also available raw via $page->mastodonReplies(), which returns success, url, replies, count, repliesCount, favouritesCount, reblogsCount, and error.
License
MIT
