From 0f6240e2d9cd4543a1d32fab9e5b91a0bae0c6f6 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sun, 28 Jan 2024 00:23:48 +0800 Subject: [PATCH] fix(route): Firefox release notes (#14331) --- lib/v2/firefox/release.js | 20 +++++++++++++------- lib/v2/firefox/router.js | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/v2/firefox/release.js b/lib/v2/firefox/release.js index b24c09000daa1d..8aaa55415487bd 100644 --- a/lib/v2/firefox/release.js +++ b/lib/v2/firefox/release.js @@ -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`, diff --git a/lib/v2/firefox/router.js b/lib/v2/firefox/router.js index eab755767e517f..49b3d0c6e5e534 100644 --- a/lib/v2/firefox/router.js +++ b/lib/v2/firefox/router.js @@ -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')); };