Skip to content

Commit

Permalink
feat(route): add 湖南日报 (DIYgod#9417)
Browse files Browse the repository at this point in the history
* feat(route): add 湖南日报

* docs: update category

* update docs/traditional-media.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
  • Loading branch information
2 people authored and RikkaBlue committed Apr 9, 2022
1 parent 40f6401 commit 466848c
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,27 @@ Type 栏目:

</Route>

## 湖南日报

### 电子刊物

<Route author="nczitzk" example="/hnrb" path="/hnrb/:id?" :paramsDesc="['编号,见下表,默认为全部']" anticrawler="1">

|| 编号 |
| ------------ | -- |
| 全部 | |
| 第 01 版:头版 | 1 |
| 第 02 版:要闻 | 2 |
| 第 03 版:要闻 | 3 |
| 第 04 版:深度 | 4 |
| 第 05 版:市州 | 5 |
| 第 06 版:理论・学习 | 6 |
| 第 07 版:观察 | 7 |
| 第 08 版:时事 | 8 |
| 第 09 版:中缝 | 9 |

</Route>

## 华尔街见闻

### 华尔街见闻
Expand Down
85 changes: 85 additions & 0 deletions lib/v2/hnrb/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const id = ctx.params.id;

const rootUrl = 'https://hnrb.voc.com.cn';
const currentUrl = `${rootUrl}/hnrb_epaper`;

let response = await got({
method: 'get',
url: currentUrl,
});

response = await got({
method: 'get',
url: `${currentUrl}/${id ? response.data.match(/URL=(.*)"/)[1].replace(/node_\d+\.htm$/, `node_20${id}.htm`) : response.data.match(/URL=(.*)"/)[1]}`,
});

const $ = cheerio.load(response.data);

const matches = response.data.match(/images\/(\d{4}-\d{2}\/\d{2})\/\d{2}\/\d+_brief/);
const link = `${rootUrl}/hnrb_epaper/html/${matches[1]}`;

let items = $('tbody')
.eq(1)
.find('a')
.toArray()
.map((a) => `${link}/${$(a).attr('href').replace(/\.\//, '')}`)
.filter((a) => /div=-1$/.test(a));

if (!id) {
await Promise.all(
$('#pageLink')
.slice(1)
.toArray()
.map((p) => `${link}/${$(p).attr('href').replace(/\.\//, '')}`)
.map(async (p) => {
const pageResponse = await got({
method: 'get',
url: p,
});

const page = cheerio.load(pageResponse.data);

items.push(
...page('tbody')
.eq(1)
.find('a')
.toArray()
.map((a) => `${link}/${page(a).attr('href').replace(/\.\//, '')}`)
.filter((a) => /div=-1$/.test(a))
);
})
);
}

items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item, async () => {
const detailResponse = await got({
method: 'get',
url: item,
});

const content = cheerio.load(detailResponse.data);

return {
link: item,
title: content('.font01').text(),
description: content('#ozoom').html(),
pubDate: timezone(parseDate(matches[1], 'YYYY-MM/DD'), +8),
};
})
)
);

ctx.state.data = {
title: `湖南日报${id ? ` - ${$('strong').first().parent().text()}` : ''}`,
link: currentUrl,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/hnrb/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:id?': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/hnrb/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'voc.com.cn': {
_name: '华声在线',
'.': [
{
title: '湖南日报',
docs: 'https://docs.rsshub.app/journal.html#hu-nan-ri-bao-dian-zi-kan-wu',
source: ['/'],
target: '/hnrb/:id',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/hnrb/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:id?', require('./index'));
};

0 comments on commit 466848c

Please sign in to comment.