sebsel / kirby-micropub

A Micropub Endpoint for Kirby 2
10 stars 0 forks source link

Auto-Git trigger #18

Open AlexKucera opened 7 years ago

AlexKucera commented 7 years ago

Hi Sebastian,

me again. :)

I see that you at least took a look at the Auto-Git plugin. Do you know of a way to make your plugin trigger the Auto-Git routine?

Pedro the developer mentions something that looks to be a simple line of code to make it work. I have just no idea where to put it. :)

Auto Git uses Kirby hooks to detect changes:

kirby()->set('hook', 'panel.page.create', function ($page) {
    autogit()->save('page.create', $page);
});

The save method runs git add -all content/ followed by a git commit -m 'Message goes here'. 
So yes, it would get committed on the next change done via the panel.

Other plugins could call the save method as well. 
Maybe I can make that even easier and more customisable.
sebsel commented 7 years ago

Well, I have seen Auto-Git, but I have not used it myself yet.

I already trigger a hook in /lib/endpoint.php#L302, but it seems that that is insufficient. It's a weird choice of params I chose, so I need to change that.

The solution should be, in your config.php (note the 'micropub'):

kirby()->hook('micropub.page.create', function ($page) {
    autogit()->save('page.create', $page->uri());
});
kirby()->hook('micropub.page.update', function ($page) {
    autogit()->save('page.update', $page->uri());
});

Please note that this does not work yet. I need to make some changes to the Micropub plugin.

Edit: Note to self, I took the code from https://github.com/pedroborges/kirby-autogit/blob/f36e5bcdc2d8da1fc7c56f1a0f9a636e7673129a/lib/hooks.php

AlexKucera commented 7 years ago

Cool. I have a very crude way involving Cron jobs working right now. But this sounds very promising.

sebsel commented 7 years ago

Just pushed a commit (https://github.com/sebsel/kirby-micropub/commit/d3473c487342e67e922d5c5a362bbb6343d92b46) to fix this. Hope it works.