mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
feat: ChinaFile (#6068)
This commit is contained in:
@@ -108,6 +108,20 @@ Refer to [Chicago Tribune's feed page](https://www.chicagotribune.com/about/ct-c
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## ChinaFile
|
||||
|
||||
### Reporting & Opinion
|
||||
|
||||
<RouteEn author="oppilate" example="/chinafile/all" path="/chinafile/:category?" :paramsDesc="['Category, by default `all`']">
|
||||
|
||||
Generates full-text feeds that the official feed doesn't provide.
|
||||
|
||||
| All | The China NGO Project |
|
||||
| --- | --------------------- |
|
||||
| all | ngo |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## NHK
|
||||
|
||||
### News Web Easy
|
||||
|
||||
@@ -91,6 +91,18 @@ pageClass: routes
|
||||
|
||||
</Route>
|
||||
|
||||
## ChinaFile
|
||||
|
||||
<Route author="oppilate" example="/chinafile/all" path="/chinafile/:category?" :paramsDesc="['分类,默认 `all`']">
|
||||
|
||||
通过提取文章全文,以提供比官方源更佳的阅读体验。
|
||||
|
||||
| 全部 | The China NGO Project |
|
||||
| ---- | --------------------- |
|
||||
| all | ngo |
|
||||
|
||||
</Route>
|
||||
|
||||
## e 公司
|
||||
|
||||
### 快讯
|
||||
|
||||
@@ -3444,4 +3444,7 @@ router.get('/gov/harbin/kjj', require('./routes/gov/harbin/kjj'));
|
||||
// WSJ
|
||||
router.get('/wsj/:lang/:category', require('./routes/wsj/index'));
|
||||
|
||||
// China File
|
||||
router.get('/chinafile/:category?', require('./routes/chinafile/index'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
69
lib/routes/chinafile/index.js
Normal file
69
lib/routes/chinafile/index.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const Parser = require('rss-parser');
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category || 'all';
|
||||
const rssUrl = `https://feeds.feedburner.com/chinafile/${category}`;
|
||||
|
||||
// The custom UA in @/utils/parser (mimic browser) results in a HTML page
|
||||
// which cannot be parsed
|
||||
const parser = new Parser();
|
||||
const feed = await parser.parseURL(rssUrl);
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
let url = item.link;
|
||||
const response = await got({ url });
|
||||
const html = response.body;
|
||||
const $ = cheerio.load(html);
|
||||
const content = $('article');
|
||||
|
||||
// Cover
|
||||
const cover = $('.view-featured-photo');
|
||||
|
||||
if (cover.length > 0) {
|
||||
cover.insertBefore(content[0].childNodes[0]);
|
||||
$(cover).remove();
|
||||
}
|
||||
|
||||
// Summary
|
||||
const summary = $('meta[name="description"]').attr('content');
|
||||
const updatedAt = $('meta[name="og:updated_time"]').attr('content');
|
||||
|
||||
const categories = $('meta[name="news_keywords"]')
|
||||
.attr('content')
|
||||
.split(',')
|
||||
.map((c) => c.trim());
|
||||
|
||||
url = $('link[rel="canonical"]').attr('href');
|
||||
|
||||
return {
|
||||
title: item.title,
|
||||
id: item.guid,
|
||||
pubDate: item.pubDate,
|
||||
updated: updatedAt,
|
||||
author: item.creator,
|
||||
link: url,
|
||||
summary: summary,
|
||||
description: content.html(),
|
||||
category: categories,
|
||||
icon: 'https://www.chinafile.com/sites/default/files/chinafile_favicon.png',
|
||||
logo: 'https://www.chinafile.com/sites/all/themes/cftwo/assets/images/logos/logo-large.png',
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: feed.title,
|
||||
link: feed.link,
|
||||
description: feed.description,
|
||||
item: items,
|
||||
language: 'en-us',
|
||||
icon: 'https://www.chinafile.com/sites/default/files/chinafile_favicon.png',
|
||||
logo: 'https://www.chinafile.com/sites/all/themes/cftwo/assets/images/logos/logo-large.png',
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user