National Geographic RSS support (#389)
* National Geographic RSS * fix format warning * docs * full text by default && correct docs * format fix ci check * correct docs
This commit is contained in:
parent
2a289ed3d1
commit
ef8ccc9d82
|
|
@ -4,6 +4,7 @@ error.log
|
|||
combined.log
|
||||
package-lock.json
|
||||
.vscode
|
||||
.idea
|
||||
docs/.vuepress/dist
|
||||
|
||||
config/app.json
|
||||
|
|
|
|||
|
|
@ -180,11 +180,11 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
|||
- 公告通知
|
||||
- 机核网
|
||||
- 分类
|
||||
- 国家地理 National Geographic
|
||||
- 分类
|
||||
- ONE · 一个
|
||||
- Firefox
|
||||
- Release note
|
||||
|
||||
</details>
|
||||
- Firefox - Release note
|
||||
</details>
|
||||
|
||||
## 鸣谢
|
||||
|
||||
|
|
|
|||
|
|
@ -1490,6 +1490,22 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到
|
|||
| ---- | ---- | ---- |
|
||||
| 1 | 2 | 9 |
|
||||
|
||||
## 国家地理 National Geographic
|
||||
|
||||
### 分类
|
||||
|
||||
举例:
|
||||
|
||||
[https://rsshub.app/natgeo/travel](https://rsshub.app/natgeo/travel)
|
||||
|
||||
[https://rsshub.app/natgeo/news/ngnews](https://rsshub.app/natgeo/news/ngnews)
|
||||
|
||||
路由: `/natgeo/:cat/:type?/:option?`
|
||||
|
||||
参数: cat, 分类; type, 类型
|
||||
|
||||
可在 url 中获取,例如`https://www.natgeomedia.com/category/news/ngnews`对应 cat, type 分别为 news, ngnews
|
||||
|
||||
## ONE · 一个
|
||||
|
||||
举例: [https://rsshub.app/one](https://rsshub.app/one)
|
||||
|
|
|
|||
|
|
@ -342,6 +342,9 @@ router.get('/pku/eecs/:type?', require('./routes/pku/eecs'));
|
|||
// 机核
|
||||
router.get('/gcores/category/:category', require('./routes/gcores/category'));
|
||||
|
||||
// 国家地理 National Geographic
|
||||
router.get('/natgeo/:cat/:type?', require('./routes/natgeo/natgeo'));
|
||||
|
||||
// 一个
|
||||
router.get('/one', require('./routes/one/index'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
const axios_ins = axios.create({
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
Reference: 'https://www.natgeomedia.com',
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = `${ctx.params.type ? ctx.params.type : ''}`;
|
||||
const url = `https://www.natgeomedia.com/category/${ctx.params.cat}/${type}`;
|
||||
const res = await axios_ins.get(url);
|
||||
const data = res.data;
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const list = $('.td-ss-main-content').find('.td-animation-stack');
|
||||
|
||||
const out = [];
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const each = $(list[i]);
|
||||
const storyLink = each.find('a[itemprop=url]').attr('href');
|
||||
const item = {
|
||||
title: each.find('a[itemprop=url]').attr('title'),
|
||||
pubDate: each.find('time').attr('datetime'),
|
||||
link: storyLink,
|
||||
guid: storyLink.match(/\d+/g)[0],
|
||||
};
|
||||
const key = `${ctx.params.cat}${type}${item.guid}`;
|
||||
const value = await ctx.cache.get(key);
|
||||
if (value) {
|
||||
item.description = value;
|
||||
} else {
|
||||
// 获取全文
|
||||
const storyDetail = await axios_ins.get(item.link);
|
||||
const data = storyDetail.data;
|
||||
const $ = cheerio.load(data);
|
||||
item.description = $('.td-post-content').html();
|
||||
ctx.cache.set(key, item.description, 12 * 60 * 60);
|
||||
}
|
||||
out.push(item);
|
||||
}
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue