diff --git a/app/Http/Controllers/FeedsController.php b/app/Http/Controllers/FeedsController.php index 9aeb4abb..a30c89dc 100644 --- a/app/Http/Controllers/FeedsController.php +++ b/app/Http/Controllers/FeedsController.php @@ -7,13 +7,66 @@ 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(): JsonResponse + public function blogJson(): array { $articles = Article::where('published', '1')->latest('updated_at')->take(20)->get(); $data = [ @@ -41,15 +94,13 @@ class FeedsController extends Controller ]; } - return response()->json($data, 200, [ - 'Content-Type' => 'application/feed+json', - ]); + return $data; } /** * Returns the notes JSON feed. */ - public function notesJson(): JsonResponse + public function notesJson(): array { $notes = Note::latest()->with('media', 'place', 'tags')->take(20)->get(); $data = [ @@ -79,9 +130,7 @@ class FeedsController extends Controller } } - return response()->json($data, 200, [ - 'Content-Type' => 'application/feed+json', - ]); + return $data; } /** diff --git a/app/Services/ArticleService.php b/app/Services/ArticleService.php index 2372ffb7..3d5dcc56 100644 --- a/app/Services/ArticleService.php +++ b/app/Services/ArticleService.php @@ -13,7 +13,7 @@ class ArticleService return Article::create([ 'title' => $data['name'], 'main' => $data['content'], - 'published' => ($data['post-status'] ?? null) !== 'draft', + 'published' => true, ]); } } diff --git a/app/Services/Micropub/Data/EntryData.php b/app/Services/Micropub/Data/EntryData.php index 192c50f7..52dde72d 100644 --- a/app/Services/Micropub/Data/EntryData.php +++ b/app/Services/Micropub/Data/EntryData.php @@ -24,7 +24,6 @@ class EntryData extends MicropubData public readonly mixed $checkin, public readonly mixed $syndication, public readonly ?array $photos, - public readonly ?string $postStatus, ) {} public static function fromRequest(Request $request): static @@ -50,7 +49,6 @@ class EntryData extends MicropubData checkin: Arr::get($data, 'properties.checkin.0'), syndication: Arr::get($data, 'properties.syndication.0'), photos: Arr::get($data, 'properties.photo'), - postStatus: Arr::get($data, 'properties.post-status.0'), ); } @@ -69,7 +67,6 @@ class EntryData extends MicropubData checkin: $request->input('checkin'), syndication: $request->input('syndication'), photos: $request->input('photos'), - postStatus: $request->input('post-status'), ); } @@ -103,7 +100,6 @@ class EntryData extends MicropubData checkin: $data['checkin'] ?? null, syndication: $data['syndication'] ?? null, photos: $data['photos'] ?? null, - postStatus: $data['post-status'] ?? null, ); } @@ -124,7 +120,6 @@ class EntryData extends MicropubData 'checkin' => $this->checkin, 'syndication' => $this->syndication, 'photos' => $this->photos, - 'post-status' => $this->postStatus, ]; } } diff --git a/resources/views/articles/atom.blade.php b/resources/views/articles/atom.blade.php new file mode 100644 index 00000000..9892bcfb --- /dev/null +++ b/resources/views/articles/atom.blade.php @@ -0,0 +1,20 @@ + + + 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 new file mode 100644 index 00000000..00268681 --- /dev/null +++ b/resources/views/articles/rss.blade.php @@ -0,0 +1,26 @@ + + + + {{ 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 deleted file mode 100644 index 7b8df856..00000000 --- a/resources/views/icons/json-feed.blade.php +++ /dev/null @@ -1,11 +0,0 @@ -@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 3c82845b..2e5c6b5a 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -7,9 +7,13 @@ @yield('title'){{ config('app.name') }} - + + + - + + + @@ -36,7 +40,7 @@ Likes Contacts Projects - @include('icons.json-feed', ['title' => 'JSON Feed']) + @include('icons.rss', ['title' => 'RSS Feed'])