Skip to content

Commit

Permalink
Add an RSS feed to the app but don't expose it yet in the html
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed Sep 13, 2024
1 parent f7f3ef0 commit f304948
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/classes/ReleaseInsights/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}

Expand Down
1 change: 1 addition & 0 deletions app/classes/ReleaseInsights/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/rss.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use ReleaseInsights\{Model, Template};

[$latest_release_date, $releases] = (new Model('rss'))->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();
38 changes: 38 additions & 0 deletions app/models/rss.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use ReleaseInsights\Data;

$data = new Data();

// We reformat the data to the same format as getDotReleases() before merging them
$major_releases = [];
foreach ($data->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];
26 changes: 26 additions & 0 deletions app/views/templates/releases.rss.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<rss version="2.0">
<channel>
<title>{{ title }}</title>
<description>{{ description }}</description>
<link>{{ site_link }}</link>
<language>en-US</language>
<lastBuildDate>{{ latest_release_date }}</lastBuildDate>
<ttl>1440</ttl>
{% for release in releases %}
<item>
<title>Firefox {{ release.version }}</title>
<description>
Firefox release {{ release.version }} shipped on {{ release.date|format_date(pattern='MMMM d, YYYY', locale='en') }}
{% if release.platform == 'android' %}&lt;br&gt;This is an Android-only release{% endif %}
{% if release.platform == 'desktop' %}&lt;br&gt;This is a desktop-only release{% endif %}
</description>
{% if release.platform == 'android' %}
<link>https://www.mozilla.org/en-US/firefox/android/{{ release.version }}/releasenotes/</link>
{% else %}
<link>{{ release.relnotes }}</link>
{% endif %}
<pubDate>{{ release.date }}</pubDate>
</item>
{% endfor %}
</channel>
</rss>
1 change: 1 addition & 0 deletions tests/Functional/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
['calendar/release/schedule/?version=beta', 200, 'BEGIN:VCALENDAR', 'END:VCALENDAR'],
['sitemap/', 301, '', ''],
['sitemap.txt', 200, '', ''],
['rss/', 200, '<rss version="2.0">', '</item>'],
];

$obj = new \pchevrel\Verif('Check public pages HTTP responses and content');
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/ReleaseInsights/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit f304948

Please sign in to comment.