feat: add boston.com (#5096)

This commit is contained in:
oppilate 2020-07-07 17:14:26 +08:00 committed by GitHub
parent 47a854e1f6
commit f789c4b9fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 0 deletions

View File

@ -26,6 +26,17 @@ Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/1062
</RouteEn>
## Boston.com
### News
<RouteEn author="oppilate" example="/boston/technology" path="/boston/:tag?" :paramsDesc="['Tag']">
Generates full-text feeds that the official feed doesn't provide.
Refer to [Boston.com's feed page](https://www.boston.com/rss-feeds) for tags. For instance, `https://www.boston.com/tag/local-news/?feed=rss` corresponds to `/boston/local-news`.
</RouteEn>
## Chicago Tribune
### News
@ -35,6 +46,7 @@ Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/1062
Generates full-text that the official feed doesn't provide.
Refer to [Chicago Tribune's feed page](https://www.chicagotribune.com/about/ct-chicago-tribune-rss-feeds-htmlstory.html) for categories. For instance, `https://www.chicagotribune.com/arcio/rss/category/nation-world/` corresponds to `/chicagotribune/nation-world`.
</RouteEn>
## China Dialogue

View File

@ -32,6 +32,17 @@ pageClass: routes
</Route>
## Boston.com
### 新闻
<Route author="oppilate" example="/boston/technology" path="/boston/:tag?" :paramsDesc="['Tag']">
生成官方未提供的全文订阅点。
有哪些 tag 请参考 [Boston.com 官网上的订阅页面](https://www.boston.com/rss-feeds)。例如,`https://www.boston.com/tag/local-news/?feed=rss` 对应 RSSHub 路由 `/boston/local-news`
</Route>
## Chicago Tribune
### 新闻

View File

@ -2874,6 +2874,9 @@ router.get('/jike/user/:id', require('./routes/jike/user'));
// 网易新闻
router.get('/netease/news/rank/:category?/:type?/:time?', require('./routes/netease/news/rank'));
// Boston.com
router.get('/boston/:tag?', require('./routes/boston/index'));
// 中国邮政速递物流
router.get('/ems/news', require('./routes/ems/news'));

View File

@ -0,0 +1,74 @@
const cheerio = require('cheerio');
const parser = require('@/utils/rss-parser');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const tag = ctx.params.tag;
const rssUrl = tag ? `https://www.boston.com/tag/${tag}/?feed=atom` : `https://www.boston.com/?feed=atom`;
const feed = await parser.parseURL(rssUrl);
const items = await Promise.all(
feed.items.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const response = await got({
url: item.link,
method: 'get',
});
const html = response.body;
const $ = cheerio.load(html);
const content = $('div.content-text-article');
// Disable image lazyloading
content.find('img').each((i, e) => {
e = $(e);
e.attr('src', e.attr('srcset'));
});
// Categories
const categories = [];
$('meta[property="article:tag"]').each((i, e) => {
categories.push(e.attribs.content);
});
// Updated date
const updatedAt = $('meta[property="article:modified_time"]').attr().content;
// Summary
const summary = $('meta[property="og:description"]').attr().content;
// Remove unwanted DOMs
const unwanted_element_selectors = ['.ad-container', '.content-toaster--newsletter'];
unwanted_element_selectors.forEach((selector) => {
content.find(selector).each((i, e) => {
$(e).remove();
});
});
return {
title: item.title.trim(),
id: item.link,
pubDate: new Date(item.pubDate).toUTCString(),
updated: new Date(updatedAt).toUTCString(),
author: item.author.trim(),
link: item.link,
summary: summary.trim(),
description: content.html(),
category: categories,
icon: 'https://www.boston.com/wp-content/themes/bdc/images/favicons/largetile.png',
logo: 'https://www.boston.com/wp-content/themes/bdc/images/favicons/largetile.png',
};
})
)
);
ctx.state.data = {
title: feed.title,
link: feed.link,
description: feed.description,
item: items,
language: 'en-us',
icon: 'https://www.boston.com/wp-content/themes/bdc/images/favicons/largetile.png',
logo: 'https://www.boston.com/wp-content/themes/bdc/images/favicons/largetile.png',
};
};