diff --git a/app/Http/Controllers/FeedsController.php b/app/Http/Controllers/FeedsController.php index a30c89dc..9aeb4abb 100644 --- a/app/Http/Controllers/FeedsController.php +++ b/app/Http/Controllers/FeedsController.php @@ -7,66 +7,13 @@ namespace App\Http\Controllers; use App\Models\Article; use App\Models\Note; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Response; class FeedsController extends Controller { - /** - * Returns the blog RSS feed. - */ - public function blogRss(): Response - { - $articles = Article::where('published', '1')->latest('updated_at')->take(20)->get(); - $buildDate = $articles->first()->updated_at->toRssString(); - - return response() - ->view('articles.rss', compact('articles', 'buildDate')) - ->header('Content-Type', 'application/rss+xml; charset=utf-8'); - } - - /** - * Returns the blog Atom feed. - */ - public function blogAtom(): Response - { - $articles = Article::where('published', '1')->latest('updated_at')->take(20)->get(); - - return response() - ->view('articles.atom', compact('articles')) - ->header('Content-Type', 'application/atom+xml; charset=utf-8'); - } - - /** - * Returns the notes RSS feed. - */ - public function notesRss(): Response - { - $notes = Note::latest()->take(20)->get(); - $buildDate = $notes->first()->updated_at->toRssString(); - - return response() - ->view('notes.rss', compact('notes', 'buildDate')) - ->header('Content-Type', 'application/rss+xml; charset=utf-8'); - } - - /** - * Returns the notes Atom feed. - */ - public function notesAtom(): Response - { - $notes = Note::latest()->take(20)->get(); - - return response() - ->view('notes.atom', compact('notes')) - ->header('Content-Type', 'application/atom+xml; charset=utf-8'); - } - - /** @todo sort out return type for json responses */ - /** * Returns the blog JSON feed. */ - public function blogJson(): array + public function blogJson(): JsonResponse { $articles = Article::where('published', '1')->latest('updated_at')->take(20)->get(); $data = [ @@ -94,13 +41,15 @@ class FeedsController extends Controller ]; } - return $data; + return response()->json($data, 200, [ + 'Content-Type' => 'application/feed+json', + ]); } /** * Returns the notes JSON feed. */ - public function notesJson(): array + public function notesJson(): JsonResponse { $notes = Note::latest()->with('media', 'place', 'tags')->take(20)->get(); $data = [ @@ -130,7 +79,9 @@ class FeedsController extends Controller } } - return $data; + return response()->json($data, 200, [ + 'Content-Type' => 'application/feed+json', + ]); } /** diff --git a/resources/views/articles/atom.blade.php b/resources/views/articles/atom.blade.php deleted file mode 100644 index 9892bcfb..00000000 --- a/resources/views/articles/atom.blade.php +++ /dev/null @@ -1,20 +0,0 @@ - - - Atom feed for {{ config('user.display_name') }}’s blog - - {{ config('app.url')}}/blog - {{ $articles[0]->updated_at->toAtomString() }} - -@foreach($articles as $article) - - {{ $article->title }} - - {{ config('app.url') }}{{ $article->link }} - {{ $article->updated_at->toAtomString() }} - {{ $article->main }} - - {{ config('user.display_name') }} - - -@endforeach - diff --git a/resources/views/articles/rss.blade.php b/resources/views/articles/rss.blade.php deleted file mode 100644 index 00268681..00000000 --- a/resources/views/articles/rss.blade.php +++ /dev/null @@ -1,26 +0,0 @@ - - - - {{ config('user.display_name') }} - - An RSS feed of the blog posts found on {{ config('app.url') }} - {{ config('app.url') }}/blog - {{ $buildDate }} - 1800 - -@foreach($articles as $article) - - {{ strip_tags($article->title) }} - - main }} - @if($article->url)

Permalink

@endif - ]]> -
- @if($article->url != ''){{ $article->url }}@else{{ config('app.url') }}{{ $article->link }}@endif - {{ config('app.url') }}{{ $article->link }} - {{ $article->pubdate }} -
-@endforeach -
-
diff --git a/resources/views/icons/json-feed.blade.php b/resources/views/icons/json-feed.blade.php new file mode 100644 index 00000000..7b8df856 --- /dev/null +++ b/resources/views/icons/json-feed.blade.php @@ -0,0 +1,11 @@ +@php +if (isset($title)) { + $uniqueId = bin2hex(random_bytes(6)); +} +@endphp + + @if($title){{ $title }}@endif + + diff --git a/resources/views/master.blade.php b/resources/views/master.blade.php index 2e5c6b5a..3c82845b 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -7,13 +7,9 @@ @yield('title'){{ config('app.name') }} - - - + - - - + @@ -40,7 +36,7 @@ Likes Contacts Projects - @include('icons.rss', ['title' => 'RSS Feed']) + @include('icons.json-feed', ['title' => 'JSON Feed'])