Files
RSSHub/lib/routes/9to5/subsite.js
T
2019-06-03 18:03:05 +08:00

61 lines
1.5 KiB
JavaScript

const got = require('@/utils/got');
const parser = require('@/utils/rss-parser');
const utils = require('./utils');
module.exports = async (ctx) => {
let title = '9To5',
link,
description;
switch (ctx.params.type) {
case 'mac':
link = 'https://9to5mac.com/feed';
title += 'Mac';
description = 'Apple News & Mac Rumors Breaking All Day';
break;
case 'google':
link = 'https://9to5google.com/feed';
title += 'Google';
description = 'Google, Pixel news, Android, Home, Chrome OS, apps, more';
break;
case 'toys':
link = 'https://9to5toys.com/feed';
title += 'Toys';
description = 'New Gear, reviews and deals';
break;
default:
break;
}
const feed = await parser.parseURL(link);
const items = await Promise.all(
feed.items.splice(0, 10).map(async (item) => {
const response = await got({
method: 'get',
url: item.link,
});
const description = utils.ProcessFeed(response.data);
const single = {
title: item.title,
description,
pubDate: item.pubDate,
link: item.link,
author: item['dc:creator'],
};
return Promise.resolve(single);
})
);
ctx.state.data = {
title,
link,
description,
item: items,
};
};