Show pending Komments on Mac OS
There is this handy little Mac OS Tool which can connect to API endpoints to show you things like twitter follower counts. It sits in your menu bar and refreshes from time to time. So why not use this tool, to show the number of pending comments you received?
The tool is called Radar (and costs $19). It comes with some pre defined connections you can use out of the box, but you can also add custom endpoints and use the result of the api call to show something in the ui. If the result is fitting the structure needed by the app, you can just define which field (key) should be used. If that doesn't work, you can use JavaScript to parse and/or modify the result.
We'll use that functionality to show the number of pending comments like so:
First of all, we have to tell Kirby to allow us to use Basic Auth to connect to the API. By default it uses session auth which won't work for our use case. So we have to open our config file site/config.php
and add the following:
'api' => [
'basicAuth' => true
]
This way we are able to connect to the Kirby Rest API with our user credentials. It might be a good idea to create a new user used exclusively for API calls. You may also add a role for that user. If you would like to know more about that topic, please have a look at the official Kirby documentation.
We should now be able to access the API Endpoint to get the pending comments which is:
https://YOUR-DOMAIN/api/komments/queued
So, let's open Radar and add a new entry. Click the +
in the upper right corner. In the next screen, enter the API endpoint of your site and write a cool name for that entry:
Next click the authentication tab below the url and fill in the email and password of the user with access to the API:
Click on the "Next" button.
Because the API endpoint returns a list of the pending comments we cannot use the result directly, we have to modify it using JavaScript. So please click the corresponding checkbox to do so. We then can use some simple JavaScript. Because we only want to know the number of comments, we'll just take the result and get the length of the entries:
Select how often you want to check for new data, enter an URL to a nice looking Icon (I used one of those) and hit "Save".
Congratulations! You can now see the number of pending comments in your menu bar 🥳
If you have further question, feel free to leave a comment below and I'll see it in my menu bar and may be able to help you. Also feel free to follow me on twitter so I can check if that entry is working as well 😉