Skip to content

Commit

Permalink
fix(route): fix ccreports route is empty and refactor to V2 (#8990)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docs/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa

### 要闻

<Route author="EsuRt" example="/ccreports/article" path="/ccreports"/>
<Route author="EsuRt Fatpandac" example="/ccreports/article" path="/ccreports/article"/>

## 小米

Expand Down
3 changes: 0 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2762,9 +2762,6 @@ router.get('/adnmb/:pid', lazyloadRouteHandler('./routes/adnmb/index'));
// MIT科技评论
router.get('/mittrchina/:type', lazyloadRouteHandler('./routes/mittrchina'));

// 消费者报道
router.get('/ccreports/article', lazyloadRouteHandler('./routes/ccreports'));

// iYouPort
router.get('/iyouport/article', lazyloadRouteHandler('./routes/iyouport'));
router.get('/iyouport/:category?', lazyloadRouteHandler('./routes/iyouport'));
Expand Down
40 changes: 0 additions & 40 deletions lib/routes/ccreports/index.js

This file was deleted.

41 changes: 41 additions & 0 deletions lib/v2/ccreports/index.js
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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/ccreports/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/article': ['EsuRt', 'Fatpandac'],
};
13 changes: 13 additions & 0 deletions lib/v2/ccreports/radar.js
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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ccreports/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/article', require('./index'));
};

1 comment on commit 97429ad

@vercel
Copy link

@vercel vercel bot commented on 97429ad Feb 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.