Merge branch 'release/0.16.3'
This commit is contained in:
commit
d8d604967c
4 changed files with 59 additions and 2 deletions
|
@ -121,9 +121,8 @@ class FeedsController extends Controller
|
|||
foreach ($notes as $key => $note) {
|
||||
$data['items'][$key] = [
|
||||
'id' => $note->longurl,
|
||||
'title' => $note->getOriginal('note'),
|
||||
'url' => $note->longurl,
|
||||
'content_html' => $note->note,
|
||||
'content_html' => $note->content,
|
||||
'date_published' => $note->created_at->tz('UTC')->toRfc3339String(),
|
||||
'date_modified' => $note->updated_at->tz('UTC')->toRfc3339String(),
|
||||
'author' => [
|
||||
|
|
|
@ -176,6 +176,37 @@ class Note extends Model
|
|||
return $modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the content_html for JSON feed.
|
||||
*
|
||||
* In particular we want to include media links such as images.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContentAttribute(): string
|
||||
{
|
||||
$note = $this->note;
|
||||
|
||||
foreach ($this->media as $media) {
|
||||
if ($media->type == 'image') {
|
||||
$note .= '<img src="' . $media->url . '" alt="">';
|
||||
}
|
||||
if ($media->type == 'audio') {
|
||||
$note .= '<audio src="' . $media->url . '">';
|
||||
}
|
||||
if ($media->type == 'video') {
|
||||
$note .= '<video src="' . $media->url . '">';
|
||||
}
|
||||
}
|
||||
|
||||
if ($note === null) {
|
||||
// when would $note still be blank?
|
||||
$note = 'A blank note';
|
||||
}
|
||||
|
||||
return $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the NewBase60 ID from primary ID.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
## Version 0.16.3 (2018-04-12)
|
||||
- Improve JSON feed conformance
|
||||
|
||||
## Version 0.16.2 (2018-04-07)
|
||||
- Add CORS headers as necessary in the Laravel app (as oppose to using nginx)
|
||||
- Add CSP headers
|
||||
|
|
|
@ -71,4 +71,28 @@ class FeedsTest extends TestCase
|
|||
$response = $this->get('/notes/feed.json');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Each JSON feed item must have one of `content_text` or `content_html`,
|
||||
* and whichever one they have can’t be `null`.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_json_feed_has_one_content_attribute_and_it_isnt_null()
|
||||
{
|
||||
$response = $this->get('/notes/feed.json');
|
||||
$data = json_decode($response->content());
|
||||
foreach ($data->items as $item) {
|
||||
$this->assertTrue(
|
||||
property_exists($item, 'content_text') ||
|
||||
property_exists($item, 'content_html')
|
||||
);
|
||||
if (property_exists($item, 'content_text')) {
|
||||
$this->assertNotNull($item->content_text);
|
||||
}
|
||||
if (property_exists($item, 'content_html')) {
|
||||
$this->assertNotNull($item->content_html);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue