-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(route): fix ccreports route is empty and refactor to V2 (#8990)
* Fix(route): fix route is empty and change to V2 * Fix(route): route address err in maintainer.js * Fix(route): change way to get pubDate * Fix(route): add timezone
- Loading branch information
Fatpandac
authored
Feb 5, 2022
1 parent
a9a8b2a
commit 97429ad
Showing
7 changed files
with
61 additions
and
44 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
This file was deleted.
Oops, something went wrong.
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,41 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
const rootUrl = 'https://www.ccreports.com.cn'; | ||
|
||
module.exports = async (ctx) => { | ||
const listData = await got.get(rootUrl); | ||
const $ = cheerio.load(listData.data); | ||
const list = $('div.index-four-content > div.article-box') | ||
.find('div.new-child') | ||
.map((_, item) => ({ | ||
title: $(item).find('p.new-title').text(), | ||
link: new URL($(item).find('a').attr('href'), rootUrl).href, | ||
author: $(item) | ||
.find('p.new-desc') | ||
.text() | ||
.match(/作者:(.*?)\s/)[1], | ||
})) | ||
.get(); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailData = await got.get(item.link); | ||
const $ = cheerio.load(detailData.data); | ||
item.description = $('div.pdbox').html(); | ||
item.pubDate = timezone(parseDate($('div.newbox > div.newtit > p').text(), 'YYYY-MM-DD HH:mm:ss'), +8); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '消费者报道', | ||
link: rootUrl, | ||
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 = { | ||
'/article': ['EsuRt', 'Fatpandac'], | ||
}; |
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 = { | ||
'ccreports.com.cn': { | ||
_name: '消费者报道', | ||
www: [ | ||
{ | ||
title: '要闻', | ||
docs: 'https://docs.rsshub.app/shopping.html#xiao-fei-zhe-bao-dao-yao-wen', | ||
source: ['/'], | ||
target: '/ccreports/article', | ||
}, | ||
], | ||
}, | ||
}; |
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('/article', require('./index')); | ||
}; |
97429ad
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: