An English version is available at the end of this post
Je suis tombé sur un post du Fediverse qui parle d’une petite fonctionnalité à ajouter (si on le désire) sur son site. Ça s’appelle humans.json, c’est un fichier au format JSON qui déclare “les contenus de ce site sont faits par un être humain”, et qui établit une chaîne de confiance en déclarant à la suite “les sites suivants sont aussi gérés par des êtres humains”. L’idée est pertinente et n’engage à rien, et je me suis dit que ça serait intéressant à implémenter sur mon site.
J’ai passé mon petit-déjeuner pour développer un petit plug-in Kirby pour gérer cette page. Il va définir une route /humans.json qui va servir le contenu, une redirection de la page humans-json vers humans.json, et un blueprint qui définit les vouches, les liens de confiance vers d’autres sites. Pour l’implémenter sur son site Kirby :
- copier le contenu du plugin vers le fichier
site/plugins/humans-json/index.php - copier la balise
linkdans la balise<head>de votre site (via un template ou un snippet, selon les cas) :
<link type="application/json" rel="human-json" href="<?= url('humans.json') ?>"> - créer une page qui a le slug
humans-jsonet le templatehumansjson, par exemple via la commande suivante (dans le répertoire racine du site) :
$ echo "Title: humans.json\n\n----\n" > ./content/humans-json/humansjson.txt
elle sera ensuite éditable dans le panel à l’adresse/panel/pages/humans-json
Et voilà !
<?php
Kirby::plugin('joachim-fourbi/humans-json', [
'routes' => [
[
'pattern' => 'humans.json',
'action' => function () {
$data = [
'version' => '0.1.1',
'url' => site()->url(),
];
$vouches = page('humans-json')?->vouches()?->toStructure();
if (!$vouches) return $data;
$data['vouches'] = [];
foreach($vouches as $v) {
$data['vouches'][] = [
'url' => $v->url()->value(),
'vouched_at' => $v->vouched_at()->toDate('Y-m-d'),
];
}
return $data;
}
],
[
'pattern' => 'humans-json',
'action' => function () {
go('humans.json', $code = 301);
}
],
],
'blueprints' => [
'pages/humansjson' => [
'fields' => [
'vouches' => [
'label' => 'Vouches',
'type' => 'structure',
'fields' => [
'url' => [
'label' => 'URL',
'type' => 'url',
],
'vouched_at' => [
'label' => 'Vouched at',
'type' => 'date',
],
]
]
]
],
],
]);
I stumbled upon a Fediverse post about an interesting feature to add to your website. It’s called humans.json, it’s a JSON file that says “the contents on this website are made by a human”, and establishes a trust chain by also declaring “I vouch for these websites, they’re also made by humans”. The idea’s pertinent and I felt that it’d be interesting to set up on my website.
So I spent my breakfast on this Kirby plugin for this page. The plugin defines a route, `/humans.json`, that will handle the content, a redirection from `humans-json` to `humans.json`, and a blueprint that defines the vouches field, the trust links to other websites. Here’s how to implement it on your Kirby website:
- copy the code above to a new plugin file located at `site/plugins/humans-json/index.php`
- copy the
linktag in the<head>of your website (it’s in a template or a snippet, depending on your theme):<link type="application/json" rel="human-json" href="<?= url('humans.json') ?>"> - create a page with the slug
humans-jsonand the templatehumansjson, e.g. via the following command (to be run in the website root dir) :$ echo "Title: humans.json\n\n----\n" > ./content/humans-json/humansjson.txt
The page will then be editable at the following address:/panel/pages/humans-json
Voilà!