From f304948ee08cc310090968804607ec3167416bc7 Mon Sep 17 00:00:00 2001 From: Pascal Chevrel Date: Fri, 13 Sep 2024 08:45:47 +0200 Subject: [PATCH] Add an RSS feed to the app but don't expose it yet in the html --- app/classes/ReleaseInsights/Model.php | 1 + app/classes/ReleaseInsights/Request.php | 1 + app/controllers/rss.php | 20 ++++++++++++ app/models/rss.php | 38 ++++++++++++++++++++++ app/views/templates/releases.rss.twig | 26 +++++++++++++++ tests/Functional/pages.php | 1 + tests/Unit/ReleaseInsights/RequestTest.php | 1 + 7 files changed, 88 insertions(+) create mode 100644 app/controllers/rss.php create mode 100644 app/models/rss.php create mode 100644 app/views/templates/releases.rss.twig diff --git a/app/classes/ReleaseInsights/Model.php b/app/classes/ReleaseInsights/Model.php index 8c7f2bf..8872168 100644 --- a/app/classes/ReleaseInsights/Model.php +++ b/app/classes/ReleaseInsights/Model.php @@ -35,6 +35,7 @@ public function __construct(public string $model) { 'owners' => 'release_owners.php', 'pre_firefox4_release' => 'pre4_release.php', 'past_release' => 'past_release.php', + 'rss' => 'rss.php', ]; } diff --git a/app/classes/ReleaseInsights/Request.php b/app/classes/ReleaseInsights/Request.php index a2ca2e7..fba8da3 100644 --- a/app/classes/ReleaseInsights/Request.php +++ b/app/classes/ReleaseInsights/Request.php @@ -79,6 +79,7 @@ public function getController(): string '/calendar/monthly/' => 'calendar_monthly', '/calendar/release/schedule/' => 'ics_release_schedule', '/release/owners/' => 'release_owners', + '/rss/' => 'rss', '/sitemap/' => 'sitemap', default => '404', }; diff --git a/app/controllers/rss.php b/app/controllers/rss.php new file mode 100644 index 0000000..c9174cf --- /dev/null +++ b/app/controllers/rss.php @@ -0,0 +1,20 @@ +get(); + +header("Content-Type: application/xml; charset=UTF-8"); + +(new Template( + 'releases.rss.twig', + [ + 'title' => 'Firefox Desktop and Android releases', + 'description' => 'Release dates for Firefox Desktop and Android. Includes major and minor releases.', + 'site_link' => 'https://whattrainisitnow.com', + 'latest_release_date' => $latest_release_date, + 'releases' => $releases, + ] +))->render(); \ No newline at end of file diff --git a/app/models/rss.php b/app/models/rss.php new file mode 100644 index 0000000..9ee76b2 --- /dev/null +++ b/app/models/rss.php @@ -0,0 +1,38 @@ +getMajorPastReleases() as $version => $date) { + $major_releases[$version] = [ + 'date' => $date, + 'platform' => 'both', + ]; +} + +// We merge and reorder the releases to have the latest first +$releases = array_merge($major_releases, $data->getDotReleases()); +krsort($releases, SORT_NATURAL); + +// Limit our RSS feed to 30 items, roughly a year of releases +$releases = array_slice($releases, 0, 30); + +$rss = []; +foreach ($releases as $key => $values) { + $rss[] = [ + 'date' => (new DateTime($values['date']))->setTime(13, 0)->format(DateTime::RFC822), + 'version' => $key, + 'platform' => $values['platform'], + 'relnotes' => 'https://www.mozilla.org/en-US/firefox/' . $key . '/releasenotes/', + ]; +} + +// We take the last update to the feed as the first item (latest release) in the sorted array +$latest_release_date = (new DateTime(reset($releases)['date']))->setTime(13,0)->format(DateTime::RFC822); + +return [$latest_release_date, $rss]; \ No newline at end of file diff --git a/app/views/templates/releases.rss.twig b/app/views/templates/releases.rss.twig new file mode 100644 index 0000000..485997e --- /dev/null +++ b/app/views/templates/releases.rss.twig @@ -0,0 +1,26 @@ + + + {{ title }} + {{ description }} + {{ site_link }} + en-US + {{ latest_release_date }} + 1440 + {% for release in releases %} + + Firefox {{ release.version }} + + Firefox release {{ release.version }} shipped on {{ release.date|format_date(pattern='MMMM d, YYYY', locale='en') }} + {% if release.platform == 'android' %}<br>This is an Android-only release{% endif %} + {% if release.platform == 'desktop' %}<br>This is a desktop-only release{% endif %} + + {% if release.platform == 'android' %} + https://www.mozilla.org/en-US/firefox/android/{{ release.version }}/releasenotes/ + {% else %} + {{ release.relnotes }} + {% endif %} + {{ release.date }} + + {% endfor %} + + \ No newline at end of file diff --git a/tests/Functional/pages.php b/tests/Functional/pages.php index 0d36902..69b7eae 100644 --- a/tests/Functional/pages.php +++ b/tests/Functional/pages.php @@ -22,6 +22,7 @@ ['calendar/release/schedule/?version=beta', 200, 'BEGIN:VCALENDAR', 'END:VCALENDAR'], ['sitemap/', 301, '', ''], ['sitemap.txt', 200, '', ''], + ['rss/', 200, '', ''], ]; $obj = new \pchevrel\Verif('Check public pages HTTP responses and content'); diff --git a/tests/Unit/ReleaseInsights/RequestTest.php b/tests/Unit/ReleaseInsights/RequestTest.php index 48ba65d..24f4769 100644 --- a/tests/Unit/ReleaseInsights/RequestTest.php +++ b/tests/Unit/ReleaseInsights/RequestTest.php @@ -30,6 +30,7 @@ ['/calendar/release/schedule', 'ics_release_schedule'], ['/release/owners', 'release_owners'], ['/release/owners', 'release_owners'], + ['/rss', 'rss'], ['/sitemap/', 'sitemap'], ['not a good path', '404'], ['not/a/goodpath', '404'],