diff --git a/app/Http/Controllers/ArticlesController.php b/app/Http/Controllers/ArticlesController.php index b88656e8..9f0c1afd 100644 --- a/app/Http/Controllers/ArticlesController.php +++ b/app/Http/Controllers/ArticlesController.php @@ -51,19 +51,4 @@ class ArticlesController extends Controller return redirect($article->link); } - - /** - * Returns the RSS feed. - * - * @return \Illuminate\Http\Response - */ - public function makeRSS() - { - $articles = Article::where('published', '1')->orderBy('updated_at', 'desc')->get(); - $buildDate = $articles->first()->updated_at->toRssString(); - - return response() - ->view('articles.rss', compact('articles', 'buildDate'), 200) - ->header('Content-Type', 'application/rss+xml'); - } } diff --git a/app/Http/Controllers/FeedsController.php b/app/Http/Controllers/FeedsController.php new file mode 100644 index 00000000..cbef048a --- /dev/null +++ b/app/Http/Controllers/FeedsController.php @@ -0,0 +1,134 @@ +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. + * + * @return \Illuminate\Http\Response + */ + public function blogAtom() + { + $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. + * + * @return \Illuminate\Http\Response + */ + public function notesRss() + { + $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. + * + * @return \Illuminate\Http\Response + */ + public function notesAtom() + { + $notes = Note::latest()->take(20)->get(); + + return response() + ->view('notes.atom', compact('notes')) + ->header('Content-Type', 'application/atom+xml; charset=utf-8'); + } + + /** + * Returns the blog JSON feed. + * + * @return \Illuminate\Http\response + */ + public function blogJson() + { + $articles = Article::where('published', '1')->latest('updated_at')->take(20)->get(); + $data = [ + 'version' => 'https://jsonfeed.org/version/1', + 'title' => 'The JSON Feed for ' . config('app.display_name') . '’s blog', + 'home_page_url' => config('app.url') . '/blog', + 'feed_url' => config('app.url') . '/blog/feed.json', + 'items' => [] + ]; + + foreach ($articles as $key => $article) { + $data['items'][$key] = [ + 'id' => config('app.url') . $article->link, + 'title' => $article->title, + 'url' => config('app.url') . $article->link, + 'content_html' => $article->main, + 'date_published' => $article->created_at->tz('UTC')->toRfc3339String(), + 'date_modified' => $article->updated_at->tz('UTC')->toRfc3339String(), + 'author' => [ + 'name' => config('app.display_name') + ] + ]; + } + + return $data; + } + + /** + * Returns the notes JSON feed. + * + * @return \Illuminate\Http\response + */ + public function notesJson() + { + $notes = Note::latest()->take(20)->get(); + $data = [ + 'version' => 'https://jsonfeed.org/version/1', + 'title' => 'The JSON Feed for ' . config('app.display_name') . '’s notes', + 'home_page_url' => config('app.url') . '/notes', + 'feed_url' => config('app.url') . '/notes/feed.json', + 'items' => [] + ]; + + foreach ($notes as $key => $note) { + $data['items'][$key] = [ + 'id' => $note->longurl, + 'title' => $note->getOriginal('note'), + 'url' => $note->longurl, + 'content_html' => $note->note, + 'date_published' => $note->created_at->tz('UTC')->toRfc3339String(), + 'date_modified' => $note->updated_at->tz('UTC')->toRfc3339String(), + 'author' => [ + 'name' => config('app.display_name') + ] + ]; + } + + return $data; + } +} diff --git a/app/Note.php b/app/Note.php index 000ccd25..ceaa15c1 100644 --- a/app/Note.php +++ b/app/Note.php @@ -168,6 +168,16 @@ class Note extends Model return config('app.shorturl') . '/notes/' . $this->nb60id; } + /** + * Get the pubdate value for RSS feeds. + * + * @return string + */ + public function getPubdateAttribute() + { + return $this->updated_at->toRSSString(); + } + /** * Get the relavent client name assocaited with the client id. * diff --git a/resources/views/articles/atom.blade.php b/resources/views/articles/atom.blade.php new file mode 100644 index 00000000..3a23d0fb --- /dev/null +++ b/resources/views/articles/atom.blade.php @@ -0,0 +1,20 @@ + + + Atom feed for {{ config('app.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('app.display_name') }} + + + @endforeach + diff --git a/resources/views/articles/rss.blade.php b/resources/views/articles/rss.blade.php index 792d8989..dff5c1f8 100644 --- a/resources/views/articles/rss.blade.php +++ b/resources/views/articles/rss.blade.php @@ -2,9 +2,9 @@ {{ config('app.display_name') }} - + An RSS feed of the blog posts found on {{ config('url.longurl') }} - {{ config('app.url') }} + {{ config('app.url') }}/blog {{ $buildDate }} 1800 diff --git a/resources/views/master.blade.php b/resources/views/master.blade.php index 2ee7e08d..2d7efe92 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -6,6 +6,12 @@ + + + + + + diff --git a/resources/views/notes/atom.blade.php b/resources/views/notes/atom.blade.php new file mode 100644 index 00000000..97909302 --- /dev/null +++ b/resources/views/notes/atom.blade.php @@ -0,0 +1,20 @@ + + + Atom feed for {{ config('app.display_name') }}’s notes + + {{ config('app.url')}}/notes + {{ $notes[0]->updated_at->toAtomString() }} + + @foreach($notes as $note) + + {{ strip_tags($note->note) }} + + {{ $note->longurl }} + {{ $note->updated_at->toAtomString() }} + {{ $note->note }} + + {{ config('app.display_name') }} + + + @endforeach + diff --git a/resources/views/notes/rss.blade.php b/resources/views/notes/rss.blade.php new file mode 100644 index 00000000..6204748b --- /dev/null +++ b/resources/views/notes/rss.blade.php @@ -0,0 +1,26 @@ + + + + {{ config('app.display_name') }} + + An RSS feed of the notes found on {{ config('url.longurl') }} + {{ config('app.url') }}/notes + {{ $buildDate }} + 1800 + + @foreach($notes as $note) + + {{ strip_tags($note->note) }} + + note !!} + ]]> + + {{ $note->longurl }} + {{ $note->longurl}} + {{ $note->pubdate }} + + @endforeach + + + diff --git a/routes/web.php b/routes/web.php index d006be26..6e777391 100644 --- a/routes/web.php +++ b/routes/web.php @@ -88,12 +88,18 @@ Route::group(['domain' => config('url.longurl')], function () { }); //Blog pages using ArticlesController + Route::get('blog/feed.rss', 'FeedsController@blogRss'); + Route::get('blog/feed.atom', 'FeedsController@blogAtom'); + Route::get('blog/feed.json', 'FeedsController@blogJson'); Route::get('blog/s/{id}', 'ArticlesController@onlyIdInURL'); Route::get('blog/{year?}/{month?}', 'ArticlesController@index'); Route::get('blog/{year}/{month}/{slug}', 'ArticlesController@show'); //Notes pages using NotesController Route::get('notes', 'NotesController@index'); + Route::get('notes/feed.rss', 'FeedsController@notesRss'); + Route::get('notes/feed.atom', 'FeedsController@notesAtom'); + Route::get('notes/feed.json', 'FeedsController@notesJson'); Route::get('notes/{id}', 'NotesController@show'); Route::get('note/{id}', 'NotesController@redirect'); Route::get('notes/tagged/{tag}', 'NotesController@tagged'); @@ -136,8 +142,6 @@ Route::group(['domain' => config('url.longurl')], function () { Route::get('places', 'PlacesController@index'); Route::get('places/{slug}', 'PlacesController@show'); - Route::get('feed', 'ArticlesController@makeRSS'); - Route::get('search', 'SearchController@search'); }); diff --git a/tests/Feature/ArticlesRSSTest.php b/tests/Feature/ArticlesRSSTest.php deleted file mode 100644 index 5bb10e35..00000000 --- a/tests/Feature/ArticlesRSSTest.php +++ /dev/null @@ -1,22 +0,0 @@ -get('/feed'); - $response->assertHeader('Content-Type', 'application/rss+xml'); - } -} diff --git a/tests/Feature/FeedsTest.php b/tests/Feature/FeedsTest.php new file mode 100644 index 00000000..df6aa98c --- /dev/null +++ b/tests/Feature/FeedsTest.php @@ -0,0 +1,77 @@ +get('/blog/feed.rss'); + $response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8'); + } + + /** + * Test the notes RSS feed. + * + * @return void + */ + public function test_notes_rss_feed() + { + $response = $this->get('/notes/feed.rss'); + $response->assertHeader('Content-Type', 'application/rss+xml; charset=utf-8'); + } + + /** + * Test the blog RSS feed. + * + * @return void + */ + public function test_blog_atom_feed() + { + $response = $this->get('/blog/feed.atom'); + $response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8'); + } + + /** + * Test the notes RSS feed. + * + * @return void + */ + public function test_notes_atom_feed() + { + $response = $this->get('/notes/feed.atom'); + $response->assertHeader('Content-Type', 'application/atom+xml; charset=utf-8'); + } + + /** + * Test the blog JSON feed. + * + * @return void + */ + public function test_blog_json_feed() + { + $response = $this->get('/blog/feed.json'); + $response->assertHeader('Content-Type', 'application/json'); + } + + /** + * Test the notes JSON feed. + * + * @return void + */ + public function test_notes_json_feed() + { + $response = $this->get('/notes/feed.json'); + $response->assertHeader('Content-Type', 'application/json'); + } +}