Skip to content

Commit

Permalink
fix(route): Firefox release notes (#14331)
Browse files Browse the repository at this point in the history
  • Loading branch information
nczitzk authored Jan 27, 2024
1 parent fc42beb commit 0f6240e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions lib/v2/firefox/release.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

const platformSlugs = {
desktop: 'releasenotes',
beta: 'beta/notes',
nightly: 'nightly/notes',
android: 'android/releasenotes',
ios: 'ios/notes',
};

module.exports = async (ctx) => {
const { platform } = ctx.params;
let devicePlatform = platform.replace('-', '/');
if (devicePlatform === 'desktop') {
devicePlatform = '';
}
const { platform = 'desktop' } = ctx.params;
const devicePlatform = platform.replace('-', '/');

const link = ['https://www.mozilla.org/en-US/firefox', devicePlatform, 'releasenotes/'].filter(Boolean).join('/');
const link = ['https://www.mozilla.org/en-US/firefox', Object.hasOwn(platformSlugs, devicePlatform) ? platformSlugs[devicePlatform] : devicePlatform].filter(Boolean).join('/');
const response = await got.get(link);
const $ = cheerio.load(response.data);
const version = $('.c-release-version').text();
const pubDate = new Date($('.c-release-date').text()).toUTCString();
const pubDate = parseDate($('.c-release-date').text(), 'MMMM D, YYYY');

ctx.state.data = {
title: `Firefox ${platform} release notes`,
Expand Down
2 changes: 1 addition & 1 deletion lib/v2/firefox/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (router) {
router.get('/addons/:id', require('./addons'));
router.get('/breaches', require('./breaches'));
router.get('/release/:platform', require('./release'));
router.get('/release/:platform?', require('./release'));
};

0 comments on commit 0f6240e

Please sign in to comment.