fix: firefox release note (#2040)

This commit is contained in:
凉凉
2019-05-06 00:59:14 +08:00
committed by DIYgod
parent 1076ebee5f
commit b073fb8d11

View File

@@ -2,36 +2,29 @@ const axios = require('../../utils/axios');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
module.exports = async (ctx) => { module.exports = async (ctx) => {
if (ctx.params.platform === 'desktop') { const { platform } = ctx.params;
ctx.params.platform = ''; let devicePlatform = platform.replace('-', '/');
if (devicePlatform === 'desktop') {
devicePlatform = '';
} }
if (ctx.params.platform === 'android-beta') {
ctx.params.platform = 'android/beta'; const link = `https://www.mozilla.org/en-US/firefox/${devicePlatform}/notes/`;
} const response = await axios.get(link);
const response = await axios.get(`https://www.mozilla.org/en-US/firefox/${ctx.params.platform}/notes/`); const $ = cheerio.load(response.data);
const data = response.data; const version = $('.c-release-version').text();
const $ = cheerio.load(data); const pubDate = new Date($('.c-release-date').text()).toUTCString();
ctx.state.data = { ctx.state.data = {
title: `Firefox ${ctx.params.platform} release note`, title: `Firefox ${platform} release note`,
link: `https://www.mozilla.org/en-US/firefox/${ctx.params.platform}/notes/`, link,
item: [ item: [
{ {
title: `Firefox ${ctx.params.platform} ${$('.version') title: `Firefox ${platform} ${version} release note`,
.find('h2') link,
.text()} release note`, description: $('.c-release-notes').html(),
link: `https://www.mozilla.org/en-US/firefox/${ctx.params.platform}/notes/`, guid: `${platform} ${version}`,
description: $('.notes-section').html(), pubDate,
guid: $('.version')
.find('h2')
.text(),
pubDate: new Date(
$('.version')
.find('p')
.text()
).toUTCString(),
}, },
], ],
description: $('.description').text(),
}; };
}; };