commit
63b1f4222c
4 changed files with 127 additions and 4 deletions
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\{Article, Note};
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class FeedsController extends Controller
|
||||
|
@ -12,7 +13,7 @@ class FeedsController extends Controller
|
|||
/**
|
||||
* Returns the blog RSS feed.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function blogRss(): Response
|
||||
{
|
||||
|
@ -27,7 +28,7 @@ class FeedsController extends Controller
|
|||
/**
|
||||
* Returns the blog Atom feed.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function blogAtom(): Response
|
||||
{
|
||||
|
@ -41,7 +42,7 @@ class FeedsController extends Controller
|
|||
/**
|
||||
* Returns the notes RSS feed.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function notesRss(): Response
|
||||
{
|
||||
|
@ -56,7 +57,7 @@ class FeedsController extends Controller
|
|||
/**
|
||||
* Returns the notes Atom feed.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function notesAtom(): Response
|
||||
{
|
||||
|
@ -133,4 +134,80 @@ class FeedsController extends Controller
|
|||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blog JF2 feed.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function blogJf2(): JsonResponse
|
||||
{
|
||||
$articles = Article::where('published', '1')->latest('updated_at')->take(20)->get();
|
||||
$items = [];
|
||||
foreach ($articles as $article) {
|
||||
$items[] = [
|
||||
'type' => 'entry',
|
||||
'published' => $article->created_at,
|
||||
'uid' => config('app.url') . $article->link,
|
||||
'url' => config('app.url') . $article->link,
|
||||
'content' => [
|
||||
'text' => $article->main,
|
||||
'html' => $article->html,
|
||||
],
|
||||
'post-type' => 'article',
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'type' => 'feed',
|
||||
'name' => 'Blog feed for ' . config('app.name'),
|
||||
'url' => url('/blog'),
|
||||
'author' => [
|
||||
'type' => 'card',
|
||||
'name' => config('user.displayname'),
|
||||
'url' => config('app.longurl'),
|
||||
],
|
||||
'children' => $items,
|
||||
], 200, [
|
||||
'Content-Type' => 'application/jf2feed+json',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the notes JF2 feed.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function notesJf2(): JsonResponse
|
||||
{
|
||||
$notes = Note::latest()->take(20)->get();
|
||||
$items = [];
|
||||
foreach ($notes as $note) {
|
||||
$items[] = [
|
||||
'type' => 'entry',
|
||||
'published' => $note->created_at,
|
||||
'uid' => $note->longurl,
|
||||
'url' => $note->longurl,
|
||||
'content' => [
|
||||
'text' => $note->getRawOriginal('note'),
|
||||
'html' => $note->note,
|
||||
],
|
||||
'post-type' => 'note',
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'type' => 'feed',
|
||||
'name' => 'Notes feed for ' . config('app.name'),
|
||||
'url' => url('/notes'),
|
||||
'author' => [
|
||||
'type' => 'card',
|
||||
'name' => config('user.displayname'),
|
||||
'url' => config('app.longurl'),
|
||||
],
|
||||
'children' => $items,
|
||||
], 200, [
|
||||
'Content-Type' => 'application/jf2feed+json',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
<link rel="alternate" type="application/rss+xml" title="Blog RSS Feed" href="/blog/feed.rss">
|
||||
<link rel="alternate" type="application/atom+xml" title="Blog Atom Feed" href="/blog/feed.atom">
|
||||
<link rel="alternate" type="application/json" title="Blog JSON Feed" href="/blog/feed.json">
|
||||
<link rel="alternate" type="application/jf2feed+json" title="Blog JF2 Feed" href="/blog/feed.jf2">
|
||||
<link rel="alternate" type="application/rss+xml" title="Notes RSS Feed" href="/notes/feed.rss">
|
||||
<link rel="alternate" type="application/atom+xml" title="Notes Atom Feed" href="/notes/feed.atom">
|
||||
<link rel="alternate" type="application/json" title="Notes JSON Feed" href="/notes/feed.json">
|
||||
<link rel="alternate" type="application/jf2feed+json" title="Notes JF2 Feed" href="/blog/feed.jf2">
|
||||
<link rel="openid.server" href="https://indieauth.com/openid">
|
||||
<link rel="openid.delegate" href="{{ config('app.url') }}">
|
||||
<link rel="authorization_endpoint" href="https://indieauth.com/auth">
|
||||
|
|
|
@ -108,6 +108,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
|||
Route::get('/feed.rss', 'FeedsController@blogRss');
|
||||
Route::get('/feed.atom', 'FeedsController@blogAtom');
|
||||
Route::get('/feed.json', 'FeedsController@blogJson');
|
||||
Route::get('/feed.jf2', 'Feedscontroller@blogJf2');
|
||||
Route::get('/s/{id}', 'ArticlesController@onlyIdInURL');
|
||||
Route::get('/{year?}/{month?}', 'ArticlesController@index');
|
||||
Route::get('/{year}/{month}/{slug}', 'ArticlesController@show');
|
||||
|
@ -119,6 +120,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
|||
Route::get('/feed.rss', 'FeedsController@notesRss');
|
||||
Route::get('/feed.atom', 'FeedsController@notesAtom');
|
||||
Route::get('/feed.json', 'FeedsController@notesJson');
|
||||
Route::get('/feed.jf2', 'FeedsController@notesJf2');
|
||||
Route::get('/{id}', 'NotesController@show');
|
||||
Route::get('/tagged/{tag}', 'NotesController@tagged');
|
||||
});
|
||||
|
|
|
@ -39,6 +39,27 @@ class FeedsTest extends TestCase
|
|||
$response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function blog_jf2_feed()
|
||||
{
|
||||
$response = $this->get('/blog/feed.jf2');
|
||||
$response->assertHeader('Content-Type', 'application/jf2feed+json');
|
||||
$response->assertJson([
|
||||
'type' => 'feed',
|
||||
'name' => 'Blog feed for ' . config('app.name'),
|
||||
'url' => url('/blog'),
|
||||
'author' => [
|
||||
'type' => 'card',
|
||||
'name' => config('user.displayname'),
|
||||
'url' => config('app.longurl'),
|
||||
],
|
||||
'children' => [[
|
||||
'type' => 'entry',
|
||||
'post-type' => 'article',
|
||||
]]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the notes RSS feed.
|
||||
*
|
||||
|
@ -72,6 +93,27 @@ class FeedsTest extends TestCase
|
|||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function notes_jf2_feed()
|
||||
{
|
||||
$response = $this->get('/notes/feed.jf2');
|
||||
$response->assertHeader('Content-Type', 'application/jf2feed+json');
|
||||
$response->assertJson([
|
||||
'type' => 'feed',
|
||||
'name' => 'Notes feed for ' . config('app.name'),
|
||||
'url' => url('/notes'),
|
||||
'author' => [
|
||||
'type' => 'card',
|
||||
'name' => config('user.displayname'),
|
||||
'url' => config('app.longurl'),
|
||||
],
|
||||
'children' => [[
|
||||
'type' => 'entry',
|
||||
'post-type' => 'note',
|
||||
]]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Each JSON feed item must have one of `content_text` or `content_html`,
|
||||
* and whichever one they have can’t be `null`.
|
||||
|
|
Loading…
Add table
Reference in a new issue