✨ Post scribbles automatically to Mastodon
All checks were successful
Deploy / deploy (push) Successful in 3s
All checks were successful
Deploy / deploy (push) Successful in 3s
This commit is contained in:
parent
d3b5609515
commit
1898705e4d
2 changed files with 63 additions and 2 deletions
|
@ -1,9 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Kirby\Cms\App as Kirby;
|
||||
use Kirby\Cms\Page;
|
||||
use Kirby\Filesystem\F;
|
||||
use Mmk2410\KirbyHelpers\Controller\ScribbleController;
|
||||
use Mmk2410\KirbyHelpers\Helpers\Mastodon;
|
||||
|
||||
F::loadClasses([
|
||||
'Mmk2410\\KirbyHelpers\\Helpers\\Mastodon' => 'src/Helpers/Mastodon.php',
|
||||
'Mmk2410\\KirbyHelpers\\RssFeed' => 'src/RssFeed.php',
|
||||
'Mmk2410\\KirbyHelpers\\Middleware\\ApiAuthentication' => 'src/Middleware/ApiAuthentication.php',
|
||||
'Mmk2410\\KirbyHelpers\\Controller\\ScribbleController' => 'src/Controller/ScribbleController.php',
|
||||
|
@ -13,8 +17,20 @@ Kirby::plugin('mmk2410/kirby-helpers', [
|
|||
'routes' => [
|
||||
[
|
||||
'pattern' => 'my/api/v1/scribble',
|
||||
'action' => fn () => (new Mmk2410\KirbyHelpers\Controller\ScribbleController())->addScribble(),
|
||||
'action' => fn () => (new ScribbleController())->addScribble(),
|
||||
'method' => 'POST'
|
||||
],
|
||||
]
|
||||
],
|
||||
'hooks' => [
|
||||
'page.changeStatus:after' => function (Page $newPage, Page $oldPage): void {
|
||||
$ignore = ($newPage->template()->name() !== 'scribble')
|
||||
|| (!$newPage->isListed())
|
||||
|| ($oldPage->status() === $newPage->status());
|
||||
if ($ignore) {
|
||||
return;
|
||||
}
|
||||
|
||||
(new Mastodon())->post($newPage);
|
||||
}
|
||||
],
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue