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