forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
National Geographic RSS support (DIYgod#389)
* National Geographic RSS * fix format warning * docs * full text by default && correct docs * format fix ci check * correct docs
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ error.log | |
combined.log | ||
package-lock.json | ||
.vscode | ||
.idea | ||
docs/.vuepress/dist | ||
|
||
config/app.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
}; |