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.
Merge pull request #743 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 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
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,53 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
const iconv = require('iconv-lite'); | ||
|
||
const rootUrl = 'http://news.inewsweek.cn'; | ||
|
||
module.exports = async (ctx) => { | ||
const channel = ctx.params.channel; | ||
const url = `${rootUrl}/${channel}`; | ||
const response = await got(url, { | ||
responseType: 'buffer', | ||
}); | ||
const $ = cheerio.load(iconv.decode(response.data, 'gbk')); | ||
const items = await Promise.all( | ||
$('div.grid-item') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
const href = item.find('a').attr('href'); | ||
const articleLink = `${rootUrl}${href}`; | ||
return ctx.cache.tryGet(articleLink, async () => { | ||
const response = await got(articleLink, { | ||
responseType: 'buffer', | ||
}); | ||
|
||
const $ = cheerio.load(iconv.decode(response.data, 'gbk')); | ||
const fullText = $('div.contenttxt').html(); | ||
const time = timezone( | ||
parseDate( | ||
$('div.editor') | ||
.html() | ||
.split(/(\s\s+)/)[2] | ||
), | ||
+8 | ||
); | ||
return { | ||
title: item.find('p').text(), | ||
description: fullText, | ||
link: articleLink, | ||
pubDate: time, | ||
}; | ||
}); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: $('title').text(), | ||
link: url, | ||
item: items, | ||
}; | ||
}; |
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,3 @@ | ||
module.exports = { | ||
'/:channel': ['changren-wcr'], | ||
}; |
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,13 @@ | ||
module.exports = { | ||
'inewsweek.cn': { | ||
_name: '中国新闻周刊', | ||
'.': [ | ||
{ | ||
title: '栏目', | ||
docs: 'https://docs.rsshub.app/traditional-media.html#zhong-guo-xin-wen-zhou-kan', | ||
source: ['/:channel', '/'], | ||
target: '/inewsweek/:channel', | ||
}, | ||
], | ||
}, | ||
}; |
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,3 @@ | ||
module.exports = function (router) { | ||
router.get('/:channel', require('./index')); | ||
}; |
2ba5ae2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rsshub-master – ./
rsshub-master.vercel.app
rsshub-master-git-master-auto-bot-ty.vercel.app
rsshub-master-auto-bot-ty.vercel.app