Skip to content

Commit c70fb8e

Browse files
committed
Implement Now RSS
1 parent e168103 commit c70fb8e

File tree

5 files changed

+110
-2
lines changed

5 files changed

+110
-2
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Support\Facades\Activity;
6+
use Illuminate\Http\Response;
7+
8+
class NowController extends Controller
9+
{
10+
public function feed(): Response
11+
{
12+
$events = Activity::events();
13+
14+
return response()
15+
->view('now.rss', ['events' => $events])
16+
->header('Content-Type', 'application/xml');
17+
}
18+
19+
public function styles(): Response
20+
{
21+
$content = file_get_contents(resource_path('assets/xsl/feed.xsl'));
22+
23+
if (empty($content)) {
24+
abort(404);
25+
}
26+
27+
return response($content)->header('Content-Type', 'text/xml');
28+
}
29+
}

resources/views/now/index.blade.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@
1515
{{ $lastModificationDate->display('date') }}
1616
</time>
1717
</span>
18+
19+
<div
20+
class="mt-2 flex flex-row gap-2 md:absolute md:top-0 md:right-0 md:flex-col"
21+
>
22+
<a
23+
class="bg-rss flex items-center justify-start rounded p-1 text-sm text-white no-underline opacity-75 hover:text-white hover:opacity-100 focus:opacity-100"
24+
href="{{ route('now.rss') }}"
25+
aria-label="Open RSS feed"
26+
title="Open RSS feed"
27+
target="_blank"
28+
>
29+
<s:partial
30+
src="icons/rss"
31+
class="inline h-4 fill-current text-white"
32+
/>
33+
</a>
34+
</div>
1835
</div>
1936

2037
<div class="max-w-readable">
@@ -37,7 +54,7 @@ class="bg-grey-lighter border-grey-light flex w-full flex-col items-center justi
3754

3855
<!-- prettier-ignore -->
3956
<p class="mt-8 mb-0 text-center text-lg">
40-
Seems like I have completed all my tasks! Come back later or check out my <a href="/tasks">previous tasks</a>.
57+
Seems like I have completed all my tasks! Come back later or check out my <a href="{{ sroute('tasks') }}">previous tasks</a>.
4158
</p>
4259
</div>
4360
@else
@@ -50,7 +67,7 @@ class="bg-grey-lighter border-grey-light flex w-full flex-col items-center justi
5067
@endforeach
5168

5269
<div class="mt-0 text-left md:-mt-8 md:text-right">
53-
<a href="/tasks">See previous tasks →</a>
70+
<a href="{{ sroute('tasks') }}">See previous tasks →</a>
5471
</div>
5572

5673
<hr class="border-grey mt-4 hidden w-full md:block" />

resources/views/now/rss.blade.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php echo '<?xml version="1.0" encoding="utf-8" ?>' . "\n"; ?>
2+
3+
<?php echo '<?xml-stylesheet type="text/xsl" href="' .
4+
route('now.xsl') .
5+
'" ?>' .
6+
"\n"; ?>
7+
8+
<feed xmlns="http://www.w3.org/2005/Atom">
9+
<title type="text">Noel De Martin [Journal]</title>
10+
<subtitle type="text">A stream of all my activity</subtitle>
11+
<updated>{!! $events[0]->date->format(DateTime::ATOM) !!}</updated>
12+
<id>{!! sroute('now') !!}</id>
13+
<link type="text/html" href="{!! sroute('now') !!}" />
14+
<link type="application/xml" rel="self" href="{!! route('now.rss') !!}" />
15+
<category term="entrepreneurship" />
16+
<category term="development" />
17+
<icon>{!! asset('favicon.ico') !!}</icon>
18+
<logo>{!! asset('img/myface-small.png') !!}</logo>
19+
<author>
20+
<name>Noel De Martin</name>
21+
<email>{{ sglobal('contact.email') }}</email>
22+
<uri>{!! sroute('home') !!}</uri>
23+
</author>
24+
@foreach ($events as $event)
25+
<entry>
26+
<title type="text">{!! $event->title !!}</title>
27+
<author>
28+
<name>Noel De Martin</name>
29+
<email>{{ sglobal('contact.email') }}</email>
30+
<uri>{!! sroute('home') !!}</uri>
31+
</author>
32+
<link href="{!! $event->url !!}" />
33+
<id>{!! $event->url !!}</id>
34+
<published>{!! $event->date->format(DateTime::ATOM) !!}</published>
35+
<updated>{!! $event->date->format(DateTime::ATOM) !!}</updated>
36+
<summary type="html">
37+
{!! htmlspecialchars($event->description) !!}
38+
</summary>
39+
<content type="html">
40+
{!! htmlspecialchars($event->longDescription) !!}
41+
</content>
42+
</entry>
43+
@endforeach
44+
</feed>

routes/web.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

33
use App\Http\Controllers\BlogController;
4+
use App\Http\Controllers\NowController;
45
use Illuminate\Support\Facades\Route;
56

67
Route::get('blog/rss.xml', [BlogController::class, 'feed'])->name('blog.rss');
78
Route::get('blog/styles.xsl', [BlogController::class, 'styles'])->name('blog.xsl');
9+
Route::get('now/rss.xml', [NowController::class, 'feed'])->name('now.rss');
10+
Route::get('now/styles.xsl', [NowController::class, 'styles'])->name('now.xsl');
811

912
Route::redirect('solid-world', 'https://www.youtube.com/watch?v=cajBTJXmKhA');
1013
Route::redirect('fosdem', 'https://www.youtube.com/watch?v=kPzhykRVDuI');

tests/Feature/NavigationTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@
6363
$response->assertSee('Reading Musashi by Eiji Yoshikawa');
6464
});
6565

66+
test('Now RSS', function () {
67+
$response = $this->get('/now/rss.xml');
68+
69+
$response->assertStatus(200);
70+
$response->assertSee('<feed xmlns="http://www.w3.org/2005/Atom">', false);
71+
$response->assertSee('Starting Something New');
72+
$response->assertSee('2014');
73+
$response->assertSee('Published');
74+
$response->assertSee('Started');
75+
$response->assertSee('Commented');
76+
$response->assertSee('Completed');
77+
$response->assertSee('Starting Something New');
78+
$response->assertSee('Reading Musashi by Eiji Yoshikawa');
79+
});
80+
6681
test('Tasks', function () {
6782
$response = $this->get('/tasks');
6883

0 commit comments

Comments
 (0)