Skip to content

Commit

Permalink
feat: add 羊城晚报金羊网 (DIYgod#11995)
Browse files Browse the repository at this point in the history
* feat: add 羊城晚报金羊网

* Fix example link of ycwb

* fix(route): 羊城晚报金羊网

* fix(route): Update lib/v2/ycwb/index.js

* fix(route): Update lib/v2/ycwb/radar.js

* fix(route): Update lib/v2/ycwb/maintainer.js

---------
  • Loading branch information
TimWu007 authored Mar 2, 2023
1 parent be06aeb commit 85eab96
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,26 @@ category 对应的关键词有

<Route author="nczitzk" example="/cctv/photo/jx" path="/cctv/photo/jx" radar="1" rssbud="1"/>

## 羊城晚报金羊网

### 新闻

<Route author="TimWu007" example="/ycwb/1" path="/ycwb/:node" :paramsDesc="['栏目 id']">

注:小部分栏目的 URL 会给出 nodeid。如未给出,可打开某条新闻链接后,查看网页源代码,搜索 nodeid 的值。

常用栏目节点:

| 首页 | 中国 | 国际 | 体育 | 要闻 | 珠江评论 | 民生观察 | 房产 | 金羊教育 | 金羊财富 | 金羊文化 | 金羊健康 | 金羊汽车 |
| -- | -- | -- | -- | -- | ---- | ----- | --- | ---- | ---- | ---- | ----- | ---- |
| 1 | 14 | 15 | 16 | 22 | 1875 | 21773 | 222 | 5725 | 633 | 5281 | 21692 | 223 |

| 广州 | 广州 - 广州要闻 | 广州 - 社会百态 | 广州 - 深读广州 | 广州 - 生活服务 | 今日大湾区 | 广东 - 政经热闻 | 广东 - 民生视点 | 广东 - 滚动新闻 |
| -- | --------- | --------- | --------- | --------- | ------ | --------- | --------- | --------- |
| 18 | 5261 | 6030 | 13352 | 83422 | 100418 | 13074 | 12252 | 12212 |

</Route>

## 中国日报

### 英语点津
Expand Down
82 changes: 82 additions & 0 deletions lib/v2/ycwb/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const node = ctx.params.node ?? 1;
const currentUrl = `https://6api.ycwb.com/app_if/jy/getArticles?nodeid=${node}&pagesize=15`;

const { data: response } = await got(currentUrl);

const list = response.artiles.map((item) => ({
title: item.TITLE,
description: art(path.join(__dirname, 'templates/description.art'), {
thumb: item.PICLINKS,
description: item.ABSTRACT,
}),
pubDate: timezone(parseDate(item.PUBTIME), +8),
link: item.PUBURL,
nodeName: item.NODENAME,
}));

let nodeName = '';
let nodeLink = '';

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

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

const $comments = content('.main_article')
.contents()
.filter(function () {
return this.nodeType === 8;
});
$comments.each(function () {
// Remove useless comments
if (this.data.match(/audioPlayer|audio-box/)) {
this.data = '';
}
// Filter author from comments
if (this.data.match(/author/)) {
item.author = this.data.split('<author>')[1].split('</author>')[0];
}
});

nodeName = nodeName === '' ? item.nodeName : nodeName;

// Filter node link from content('.path a')
const children = content('.path').children('a');
for (const child of children) {
if (content(child).text() === nodeName && nodeLink === '') {
nodeLink = content(child).attr('href');
}
}

content('span').removeAttr('style').removeAttr('class');
content('img').removeAttr('style').removeAttr('class').removeAttr('placement').removeAttr('data-toggle').removeAttr('trigger').removeAttr('referrerpolicy');
content('br').removeAttr('style').removeAttr('class');
content('p').removeAttr('style').removeAttr('class');
content('.space10, .ddf').remove();

item.description += content('.main_article').html() ?? '';

return item;
})
)
);

ctx.state.data = {
title: `羊城晚报金羊网 - ${nodeName}`,
link: String(nodeLink === '' ? 'https://www.ycwb.com/' : nodeLink),
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/ycwb/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:node': ['TimWu007'],
};
12 changes: 12 additions & 0 deletions lib/v2/ycwb/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
'xwlb.com.cn': {
_name: '羊城晚报金羊网',
'.': [
{
title: '新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#yang-cheng-wan-bao-jin-yang-wang',
source: ['/'],
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ycwb/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:node', require('./index'));
};
7 changes: 7 additions & 0 deletions lib/v2/ycwb/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ if thumb }}
<img src="{{ thumb }}"><br>
{{ /if }}
{{ if description }}
<blockquote><p>{{ description }}</p></blockquote>
<br>
{{ /if }}

0 comments on commit 85eab96

Please sign in to comment.