Log in
Seblog.nl

Seblog.nl

Day 24: media-endpoint at HWC

Today I was at Homebrew Website Club in Utrecht. We had some talks, showed some stuff, and then coded for a while. (You might say that we switched the quiet writing hour and the talks around, but we were not silent all the time.) Jesse made a first version of a blog section on his site and Martijn did some tweaking on his habit tracker.

I made it easy for myself: I just copy+pasted my existing [media endpoint](https://www.w3.org/TR/micropub/#media-endpoint) into my Indieweb Toolkit. Then I spent the rest of the time tweaking, cleaning and improving my code. The whole endpoint is now contained in a single static method, which takes a string with the path to the upload folder, and a string with the public URL of that same folder. It validates access tokens, saves media with a sanitised filename and an unguessable prefix, like vx5dgk-image.jpg, and then returns the URL of the uploaded file in a Location header.

So, this could be your media-endpoint.php:

<?php
require __DIR__ . DIRECTORY_SEPARATOR . 'toolkit' . DIRECTORY_SEPARATOR . 'bootstrap.php';
require __DIR__ . DS . 'indieweb-toolkit' . DS . 'bootstrap.php';

endpoint::media(__DIR__ . DS . 'media', 'http://indieweb-toolkit.dev/media');

Still haven't brought the IndieAuth class over to the toolkit though, so it's still not working. But it's coming!

Mijn schermloze dag is nu officieel mislukt. Ik ging van 'geen scherm' naar 'alleen telefoon', maar toen zat er een bug in de code die moet bijhouden hoe veel ik gelezen heb vandaag, dus nu zit ik toch weer achter mijn laptop, in de code, met koffie, IndieWeb-dingen te doen.

Day 23: automatic retweet

Okay, I admit: I already did this yesterday, as you can see from my previous retweet. But I wanted one day off. One day without screens. So that’s today.

Earlier on I made my site like tweets when I post a like to a tweet on my site. This means I get just feed my Micropub endpoint an URL as a like-of, and don’t think about it anymore. Now I added reposts to this too, so I can just paste a link in Quill and it’s ok.

I also seemed to miss pictures in reposts since I redid them, so I fixed that as well. It’s the little things. See you tomorrow!

Day 22: read posts

In December I already posted some plain text notes tracking my reading progress in Stoner by John Williams. (The Dutch translation, by the way, because I got that one somewhere in a very portable version and I was on a city trip to Vilnius.) I already planned to upgrade those plain text notes to a more standarized format, so that I would have /read posts.

Before I could add them, though, I needed a way to give them URLs. So now I have this public list of books I own / owned / want to track, on my new library page: /bieb. All books in there are marked up as h-cites and have a url in the format https://seblog.nl/isbn/9780123456789. Their u-uid is set to isbn:9780123456789, because that seems to be a valid url scheme (but browsers don't know what to do with it).

The next step was simple: I just expanded my shortpost type with a 'read' type, that looks for a read-of field. Thanks to XRay and my existing code, the seblog.nl/isbn/-url gets expanded to a title and author. I also added a page field, because I posted when I was at certain points at the book, and I actually haven't finished it yet.

Now my new /gelezen page looks like this:

Inzichten op de late avond: het probleem is niet dat ik niet op Facebook zit. Het probleem is dat jullie er allemaal wel op zitten, en dat normaal vinden.

En, min of meer door Tegenlicht van vanavond: zwart-wit denken los je niet op met grijstinten. Het tegenovergestelde van zwart-wit is kleur, een totaal andere manier van kijken.

En dat gaat dan dus niet over ‘Trump denkt zwart-wit’ of ‘mensen die Trump erg vinden hebben een psychose’, want dat is in zichzelf nog steeds zwart-wit. Dat relativeren (wat ik net deed) is denk ik een grijstint. Kleur is de nuance proberen te zien.

Day 21: basic Micropub endpoint

Today I added a very basic Micropub endpoint to my Indieweb Toolkit. A Micropub endpoint is a hard thing to keep generic, because every site has a different way of storing data. The idea about the endpoint in the toolkit is that it does all the things that are the same about Micropub.

So here's an example of what it can do. This one simply writes a YAML file with the received fields to a folder. Please note that it overwrites any post with an existing slug. It's only an example.

endpoint::micropub([
  'create' => function($type, $fields, $slug) {
    $map = [
      'entry' => 'blog',
      'event' => 'events',
      'review' => 'reviews',
    ];

    if(!isset($map[$type])) return false;
    if(!$slug) $slug = uniqid();

    yaml::write(__DIR__ . DS . $map[$type] . DS . $slug . '.yml', $fields);

    return url::makeAbsolute('/'.$map[$type] . '/' . $slug . '.yml');
  }
]);

The idea is that you can put this code where-ever you want. It can be at /micropub.php or in some route you define. The new endpoint::micropub() does all the authentication for you and returns the appropriate header. All you need to do is pass in a 'create' callback function, which takes the fields and returns a URL. endpoint::micropub() will do the redirect with a 201 header.

At this moment it only supports 'create' with x-www-form-urlencoded, but JSON and 'delete', 'undelete' and 'update' will follow. I also want callbacks for different mp-synticate-tos, and of course there is the ?q=config query. But I like this idea, and will use this idea to clean out the code of my own endpoint.

Last caveat: at this moment I have not implemented the IndieAuth class in my toolkit. You can steal the class from my kirby-micropub plugin, but I want to clean it first before putting it in the toolkit.

Meer laden