Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add 衡阳日报 & 衡阳晚报 #9418

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/journal.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ pageClass: routes
在 Stork 上注册并订阅关键词后,在 `我的` -> `关键词` 中可找到对应关键词的订阅 URL。URL 后的两个参数即为路由参数。

</Route>

## X-MOL 平台

### 期刊
Expand Down
38 changes: 38 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,44 @@ Type 栏目:

</Route>

## 衡阳全搜索

### 衡阳日报

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

| 版 | 编号 |
| ----------- | -- |
| 全部 | |
| 第 A01 版:版面一 | 1 |
| 第 A02 版:版面二 | 2 |
| 第 A03 版:版面三 | 3 |
| 第 A04 版:版面四 | 4 |
| 第 A05 版:版面五 | 5 |
| 第 A06 版:版面六 | 6 |
| 第 A07 版:版面七 | 7 |
| 第 A08 版:版面八 | 8 |

</Route>

### 衡阳晚报

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

| 版 | 编号 |
| ----------- | -- |
| 全部 | |
| 第 A01 版:版面一 | 1 |
| 第 A02 版:版面二 | 2 |
| 第 A03 版:版面三 | 3 |
| 第 A04 版:版面四 | 4 |
| 第 A05 版:版面五 | 5 |
| 第 A06 版:版面六 | 6 |
| 第 A07 版:版面七 | 7 |
| 第 A08 版:版面八 | 8 |

</Route>

## 华尔街见闻

### 华尔街见闻
Expand Down
89 changes: 89 additions & 0 deletions lib/v2/hyqss/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 type = ctx.params.type ?? 'hyrb';
const isDaily = type === 'hyrb';

const id = ctx.params.id;

const rootUrl = 'http://epaper.hyqss.cn';
const currentUrl = `${rootUrl}${isDaily ? '' : `/${type}`}`;

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

const url = response.data.match(/URL=(.*)"/)[1];

response = await got({
method: 'get',
url: `${currentUrl}/${id ? url.replace(/node_\d+\.htm/, `node_19${isDaily ? '62' : '74'}${id}.htm`) : url}`,
});

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

const matches = url.match(/html\/(.*)\/node/);
const link = `${rootUrl}/${isDaily ? '' : 'hywb/'}html/${matches[1]}`;

let items = $('#main-ed-articlenav-list')
.first()
.find('a')
.toArray()
.map((a) => `${link}/${$(a).attr('href')}`);

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

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

items.push(
...page('#main-ed-articlenav-list')
.first()
.find('a')
.toArray()
.map((a) => `${link}/${page(a).attr('href')}`)
);
})
);
}

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: `衡阳${isDaily ? '日' : '晚'}报${id ? ` - ${$('strong').first().parent().text()}` : ''}`,
link: currentUrl,
item: items,
allowEmpty: true,
};
};
4 changes: 4 additions & 0 deletions lib/v2/hyqss/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/hyrb/:id?': ['nczitzk'],
'/hywb/:id?': ['nczitzk'],
};
22 changes: 22 additions & 0 deletions lib/v2/hyqss/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const radars = [
{
title: '衡阳日报',
docs: 'https://docs.rsshub.app/journal.html#heng-yang-quan-sou-suo-heng-yang-ri-bao',
source: ['/'],
target: '/hnrb/hyrb/:id?',
},
{
title: '衡阳晚报',
docs: 'https://docs.rsshub.app/journal.html#heng-yang-quan-sou-suo-heng-yang-wan-bao',
source: ['/'],
target: '/hnrb/hywb/:id?',
},
];

module.exports = {
'hyqss.cn': {
_name: '衡阳全搜索',
'.': radars,
epaper: radars,
},
};
3 changes: 3 additions & 0 deletions lib/v2/hyqss/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:type?/:id?', require('./index'));
};