Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: activityPub integration #6

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Use one of these three methods to install the plugin:

* [Receiving Webmentions](docs/receiving.md)
* [Sending Webmentions](docs/sending.md)
* [Be a Mastodon Instance](docs/activitypub.md) (ActivityPub)
* [Post to Mastodon](docs/mastodon.md)
* [Subscribe to the hook](docs/hook.md)
* [All options](docs/options.md)
Expand All @@ -44,11 +45,11 @@ Use one of these three methods to install the plugin:

## Roadmap

- [ ] Connect to Mastodon (first step via https://fed.brid.gy/)
- [ ] Nested indieweb replies
- [ ] Blocklist for domains
- [ ] Blocklist for users
- [ ] Implement receiving webmentions without webmention.io
- [x] Connect to Mastodon (first step via https://fed.brid.gy/)
- [x] Kirby 3.6 ready
- [x] View Webmention stats in the panel
- [x] Send webmentions
Expand Down
70 changes: 70 additions & 0 deletions docs/activitypub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ActivityPub (beta)

IndieConnector can act as a Mastodon Instance. Once enabled, users can follow your site on a ActivityPub supporting instance, for example on Mastodon or Pixelfed. *Currently this is done by using a free open source third party service for that.*

## Prequisits

In order to be able to use this functionality, you have to provide two things, this plugin cannot do:

1. A valid Atom feed
2. microformats

You'll need a least an h-card on your site. This is used to identify you and to show your name or avatar. The most simple variant is this:

```<a href="https://YOUR-DOMAIN.tld/" class="h-card" rel="me">Your Name</a>```

You can add a lot more information if you want to. [Have a read here](https://microformats.org/wiki/h-card).

## Limitations

1. Make sure sending webmentions is enabled (this is by default)
2. IndieConnector needs to set routes for `.well-known/webfinger` and `.well-known/host-meta*`. If you already use this files you might not want to use this feature.
3. At the moment replies on mastodon won't be sent back to you. As far as I figured out, this is due to some behavior of webmention.io. I am looking for a workaround, which might be not using webmention.io at all. This will take some time.

## Setup

IndieConnector currently uses [brid.gy](https://fed.brid.gy/) to provide this functionality.

Go to [brid.gy](https://fed.brid.gy/) and select the option "**Connect directly to the fediverse**".
Enter your website url and brid.gy will peform some tests. It should prompt you to add .well-known redirects. To do so, enable activityPub in your Kirby `config.php`

```
'mauricerenck.indieConnector.activityPubBridge' => true
```

After setting this, go to brid.gy and click on check now. This should now work and the prompt should disappear.

## Publishing posts

Publishing works via webmentions. IndieConnector does this for you already. Once you enable the activityPub feature, this plugin will automatically send an additional webmention to brid.gy. The default rules (like restrictions by template) are applied. So please check those.

Please also make sure to use microformats on your site, so the content can be parsed and more than a title is shown. For example:

```
Regarding <a class="u-in-reply-to" href="https://mastodon.online/@maurice-renck.de@maurice-renck.de/109463377498963385">this post</a>:
<p class="e-content">This a reply to a mastodon post, it'll appear under the original post</p>
```

This way you can [post](https://indieweb.org/post), [reply](https://indieweb.org/reply), [like](https://indieweb.org/like), [repost](https://indieweb.org/repost) other posts or even [follow](https://indieweb.org/follow) users.

## A more detailed h-card example

Here is a more detailed example of how your h-card could look. This is from my site and I stripped away some stuff used by my UI framework.

```html
<div class="h-card>
<img class="u-photo" src="https://maurice-renck.de/media/users/4Sl6Kpjp/6d966944c9-1667809857/profile-80x.png" width="80" height="80" alt="A strange photo of Maurice Renck">
<a class="p-name u-url uk-link-reset" href="https://maurice-renck.de">Maurice Renck</a>
<ul>
<li><a href="https://mastodon.online/@mauricerenck" class="u-url" rel="me" title="mastodon" uk-tooltip="title: Mastodon @mauricerenck@mastodon.online"><span uk-icon="world"></span></a></li>
<li><a href="https://twitter.com/mauricerenck" class="u-url" rel="me" title="twitter" uk-tooltip="title: Twitter @mauricerenck"><span uk-icon="twitter"></span></a></li>
<li><a href="https://instagram.com/mauricerenck" class="u-url" rel="me" title="instagram" uk-tooltip="title: Instagram @mauricerenck"><span uk-icon="instagram"></span></a></li>
<li><a href="https://github.com/mauricerenck" class="u-url" rel="me" title="github" uk-tooltip="title: GitHub @mauricerenck"><span uk-icon="github"></span></a></li>
</ul>
<div class="p-note"><p>Maurice entwickelt Ideen &amp; Tools für digitales Storytelling und ein offenes Web. Er schreibt seit über 20 Jahren ins Internet, podcastet seit 2001. Maurice gründete ein Startup und ein Print-Magazin. Er schreibt Texte, Musik und Code.</p>
</div>
```

This will result in this:

![The result on Mastodon](mastodon-profile.png "The result on Mastodon")
2 changes: 1 addition & 1 deletion docs/hook.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hooks

IndieConnector receives (and soon sends) Webmentions. But it doesn't "do" anything with it. It's function is to handle all the stuff around Webmentions and then normalize the format and trigger a hook. Other plugins can then subscribe to this hook and use the data.
IndieConnector receives and Webmentions. But it doesn't "do" anything with it. It's function is to handle all the stuff around Webmentions and then normalize the format and trigger a hook. Other plugins can then subscribe to this hook and use the data.

The [Komments plugin]() does this, for example.

Expand Down
Binary file added docs/mastodon-profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@
| `mastodon-instance-url` | `‘‘` | Your mastodon instance url |
| `mastodon-text-field` | `‘description‘` | Source field for toot text |


## ActivityPub beta ([details](activitiypub.md))

| Option | Default | Description |
| ----------------------- | --------------- | ------------------------------- |
| `activityPubBridge` | `false` | Enable activityPub (beta) |

20 changes: 20 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,25 @@
return 'Sent! You should be able to configure your webmention.io hook now.';
}
],
[
'pattern' => '^.well-known/((host-meta|webfinger).(:any)|(host-meta|webfinger))',
'method' => 'OPTIONS|GET|POST|PUT',
'action' => function($file) {
if(!option('mauricerenck.indieConnector.activityPubBridge', false)) {
return false;
}

$query = kirby()->request()->query()->toArray();

$queryString = [];
foreach ($query as $key => $value) {
$queryString[] = $key . '=' . $value;
}

$redirectUrl = 'https://fed.brid.gy/.well-known/' . $file . '?' . implode('&', $queryString);

die(header('Location: ' . $redirectUrl));
}
]
]
]);
4 changes: 4 additions & 0 deletions internal/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

$cleanedUrls = $senderUtils->cleanupUrls($urls, $newPage);

if(option('mauricerenck.indieConnector.activityPubBridge', false)) {
$cleanedUrls[] = 'https://fed.brid.gy/';
}

if (count($cleanedUrls) === 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion site/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'debug' => true,
'url' => 'https://indieconnector.test',
'url' => 'https://indie-connector.test:8890',
'api' => [
'basicAuth' => true
],
Expand Down