Update JSON notes feed to version 1.1
This commit is contained in:
parent
24ca9f86d2
commit
2aa60db548
4 changed files with 20 additions and 13 deletions
|
@ -102,12 +102,18 @@ class FeedsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function notesJson(): array
|
public function notesJson(): array
|
||||||
{
|
{
|
||||||
$notes = Note::latest()->with('media', 'place')->take(20)->get();
|
$notes = Note::latest()->with('media', 'place', 'tags')->take(20)->get();
|
||||||
$data = [
|
$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',
|
'title' => 'The JSON Feed for ' . config('user.display_name') . '’s notes',
|
||||||
'home_page_url' => config('app.url') . '/notes',
|
'home_page_url' => config('app.url') . '/notes',
|
||||||
'feed_url' => config('app.url') . '/notes/feed.json',
|
'feed_url' => config('app.url') . '/notes/feed.json',
|
||||||
|
'authors' => [
|
||||||
|
[
|
||||||
|
'name' => config('user.display_name'),
|
||||||
|
'url' => config('app.url'),
|
||||||
|
],
|
||||||
|
],
|
||||||
'items' => [],
|
'items' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -115,13 +121,13 @@ class FeedsController extends Controller
|
||||||
$data['items'][$key] = [
|
$data['items'][$key] = [
|
||||||
'id' => $note->longurl,
|
'id' => $note->longurl,
|
||||||
'url' => $note->longurl,
|
'url' => $note->longurl,
|
||||||
'content_html' => $note->content,
|
'content_text' => $note->content,
|
||||||
'date_published' => $note->created_at->tz('UTC')->toRfc3339String(),
|
'date_published' => $note->created_at->tz('UTC')->toRfc3339String(),
|
||||||
'date_modified' => $note->updated_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;
|
return $data;
|
||||||
|
|
|
@ -144,17 +144,17 @@ class Note extends Model
|
||||||
*/
|
*/
|
||||||
public function getContentAttribute(): string
|
public function getContentAttribute(): string
|
||||||
{
|
{
|
||||||
$note = $this->note;
|
$note = $this->getRawOriginal('note');
|
||||||
|
|
||||||
foreach ($this->media as $media) {
|
foreach ($this->media as $media) {
|
||||||
if ($media->type === 'image') {
|
if ($media->type === 'image') {
|
||||||
$note .= '<img src="' . $media->url . '" alt="">';
|
$note .= PHP_EOL . '<img src="' . $media->url . '" alt="">';
|
||||||
}
|
}
|
||||||
if ($media->type === 'audio') {
|
if ($media->type === 'audio') {
|
||||||
$note .= '<audio src="' . $media->url . '">';
|
$note .= PHP_EOL . '<audio src="' . $media->url . '">';
|
||||||
}
|
}
|
||||||
if ($media->type === 'video') {
|
if ($media->type === 'video') {
|
||||||
$note .= '<video src="' . $media->url . '">';
|
$note .= PHP_EOL . '<video src="' . $media->url . '">';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,7 @@ A note with some code:
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo 'Hello World';
|
echo 'Hello World';
|
||||||
|
```
|
||||||
EOF;
|
EOF;
|
||||||
$noteWithCode = Note::create([
|
$noteWithCode = Note::create([
|
||||||
'note' => $noteWithCodeContent,
|
'note' => $noteWithCodeContent,
|
||||||
|
|
|
@ -322,7 +322,7 @@ class NotesTest extends TestCase
|
||||||
]);
|
]);
|
||||||
$note->media()->save($media);
|
$note->media()->save($media);
|
||||||
|
|
||||||
$expected = '<p>A nice image</p>
|
$expected = 'A nice image
|
||||||
<img src="' . config('filesystems.disks.s3.url') . '/test.png" alt="">';
|
<img src="' . config('filesystems.disks.s3.url') . '/test.png" alt="">';
|
||||||
$this->assertEquals($expected, $note->content);
|
$this->assertEquals($expected, $note->content);
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ class NotesTest extends TestCase
|
||||||
]);
|
]);
|
||||||
$note->media()->save($media);
|
$note->media()->save($media);
|
||||||
|
|
||||||
$expected = '<p>A nice video</p>
|
$expected = 'A nice video
|
||||||
<video src="' . config('filesystems.disks.s3.url') . '/test.mkv">';
|
<video src="' . config('filesystems.disks.s3.url') . '/test.mkv">';
|
||||||
$this->assertEquals($expected, $note->content);
|
$this->assertEquals($expected, $note->content);
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ class NotesTest extends TestCase
|
||||||
]);
|
]);
|
||||||
$note->media()->save($media);
|
$note->media()->save($media);
|
||||||
|
|
||||||
$expected = '<p>Some nice audio</p>
|
$expected = 'Some nice audio
|
||||||
<audio src="' . config('filesystems.disks.s3.url') . '/test.flac">';
|
<audio src="' . config('filesystems.disks.s3.url') . '/test.flac">';
|
||||||
$this->assertEquals($expected, $note->content);
|
$this->assertEquals($expected, $note->content);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue