Update JSON notes feed to version 1.1

This commit is contained in:
Jonny Barnes 2023-12-20 14:44:11 +00:00
parent 24ca9f86d2
commit 2aa60db548
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
4 changed files with 20 additions and 13 deletions

View file

@ -102,12 +102,18 @@ class FeedsController extends Controller
*/
public function notesJson(): array
{
$notes = Note::latest()->with('media', 'place')->take(20)->get();
$notes = Note::latest()->with('media', 'place', 'tags')->take(20)->get();
$data = [
'version' => 'https://jsonfeed.org/version/1',
'version' => 'https://jsonfeed.org/version/1.1',
'title' => 'The JSON Feed for ' . config('user.display_name') . 's notes',
'home_page_url' => config('app.url') . '/notes',
'feed_url' => config('app.url') . '/notes/feed.json',
'authors' => [
[
'name' => config('user.display_name'),
'url' => config('app.url'),
],
],
'items' => [],
];
@ -115,13 +121,13 @@ class FeedsController extends Controller
$data['items'][$key] = [
'id' => $note->longurl,
'url' => $note->longurl,
'content_html' => $note->content,
'content_text' => $note->content,
'date_published' => $note->created_at->tz('UTC')->toRfc3339String(),
'date_modified' => $note->updated_at->tz('UTC')->toRfc3339String(),
'author' => [
'name' => config('user.display_name'),
],
];
if ($note->tags->count() > 0) {
$data['items'][$key]['tags'] = implode(',', $note->tags->pluck('tag')->toArray());
}
}
return $data;