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();
// Makes it easy to implement 'create', 'update' or 'delete' in
// your endpoint
// 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();
// 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.
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!