Addpixel / KirbyComments

[Kirby 2] File-based comments stored as subpages for the Kirby CMS.
MIT License
68 stars 4 forks source link

Thanks πŸ‘ & Use Git-Commit-And-Push-Content Plugin with a Hook #38

Closed wottpal closed 7 years ago

wottpal commented 7 years ago

Just a little thank you for the ongoing efforts you put into this nice plugin. I am using it on my new personal site (e.g. here)! Transition to 1.5 was smooth and I will try out some things with Custom Fields & Nested Comments in the future.

I already re-implemented pushing to my remote repository (with the gcap-plugin) with one of the new Hooks. I just wanted to post my solution here if anyone else is in need for this:

c::set([
  'comments.hooks.did-save-comment' => function ($comments, $comment, $commentPage) {
    $should_commit = c::get('gcapc-commit', false);
    $should_push = c::get('gcapc-push', false);
    if ($should_commit && $should_push) {
      $gitHelper = new KirbyGitHelper();
      $gitHelper->kirbyChange("commented on ".$commentPage->uri());
    }
  }
]);

One thing which could be improved though is the loading time. After somebody made a comment it gets pushed & commented synchronously which definitely slows down the page-load. Any idea here? Maybe I should use something like Kirby Queue by @sebsel...

Happy Halloween πŸŽƒπŸ§›β€β™‚οΈπŸ§Ÿβ€β™‚οΈ

florianpircher commented 7 years ago

This is a great use for hooks, thanks for sharing! I think you want to change this line:

$gitHelper->kirbyChange("commented on ".$commentPage->uri());

to this:

$gitHelper->kirbyChange("commented on ".$comment->page()->uri());

This shows the difference between $commentPage and $comment->page():

content/
└─ blog/
   └─ 1-hello-world/        <-  $comment->page()
      β”œβ”€ post.txt
      └─ comments/
         β”œβ”€ comments.txt
         β”œβ”€ 1-comment-1/    <-  $commentPage
         β”‚  └─ comment.txt
         β”œβ”€ 2-comment-2/
         β”‚  └─ comment.txt
         └─ 3-comment-3/
            └─ comment.txt

Not blocking the page load sounds like a good idea but I don’t know if this can be done with Queue for Kirby as I have never used it.

I have to close this issue because it isn’t actionable. I am planning to publish a cookbook for Kirby Comments (inspired by Kirby’s cookbook) where I will include this snippet.

wottpal commented 7 years ago

Just for reference, after some minor issues I got everything working asynchronously with a queue and a cronjob. πŸŽ‰ I posted my solution here: https://github.com/sebsel/queue-for-kirby/issues/3#issuecomment-341974133.