Thanks for sharing! Interesting solution with the post-type matcher, it seems quite powerfulā¦
You are motivating me to clean up my own endpoint code and put it on githubā¦ As you wrote in the docs, itās rather hard to write this as a plug-and-play āpluginā, because every site is different. While I find it a good idea to have a very configurable plugin, I think it would be cool to modularize the implementation as strongly as possible, to join forces among us interested in developing IndieWeb stuff for Kirby.
In the implementation I currently run, I tried to take some ideas towards this from the āIndieweb Toolkit for Kirby 2ā by @seb , so people would not have to reinvent the wheel all the time.
For example, it has a Request
class which basically can be used like the Kirby Request
Object in your endpoint, only it already converts JSON and form input by the client into a handy data array, downloads attachments sent via URL, and makes everything available Kirby-style:
$request = new MicropubRequest();
if($request->is('POST')) {
// Makes it easy to implement 'create', 'update' or 'delete' in
// your endpoint
switch($request->action()) {
case 'create':
// All the properties of the post, already sanitized
$content = $request->body()->toArray();
// Access the attachments, already downloaded and ready
// as Kirby\Http\Request\Files Object
$files = $request->files();
// Supports extensions like 'post-status' for drafts
$status = $request->status();
case 'update':
// Url of the page to update available via url()
$updatePage = kirby()->pages()->find($request->url());
// and so onā¦
With this, development of any kind of endpoint is rather straightforward.
Similarly, my Endpoint
class is rather minimal and agnostic towards your siteās content structure, you pass it a ācreateā, āupdateā etc callback function which returns the url of the created post, the endpoint takes care of the rest (handling queries, responses, media-endpoint, etc).
I see the benefit of an approach like this especially in maintenance and support of new Micropub featuresā¦ Anyways, I hope I get to it soon and can share some code, and would be nice to hear what you think!