feat(route): 乌有之乡栏目 (#9030)

* feat(route): 乌有之乡栏目

* fix: 404 pages
This commit is contained in:
Ethan Shen 2022-02-09 20:06:53 +08:00 committed by GitHub
parent 1e1ff5d6d3
commit 471ea1a848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 134 additions and 0 deletions

View File

@ -3185,6 +3185,56 @@ column 为 third 时可选的 category:
<Route author="nczitzk" example="/watchout" path="/watchout"/>
## 乌有之乡
### 栏目
<Route author="nczitzk" example="/wyzxwk/article/shushe" path="/wyzxwk/article/:id?" :paramsDesc="['栏目 id可在栏目页 URL 中找到,默认为时代观察']">
时政
| 时代观察 | 舆论战争 |
| -------- | -------- |
| shidai | yulun |
经济
| 经济视点 | 社会民生 | 三农关注 | 产业研究 |
| -------- | -------- | -------- | -------- |
| jingji | shehui | sannong | chanye |
国际
| 国际纵横 | 国防外交 |
| -------- | -------- |
| guoji | guofang |
思潮
| 理想之旅 | 思潮碰撞 | 文艺新生 | 读书交流 |
| -------- | -------- | -------- | -------- |
| lixiang | sichao | wenyi | shushe |
历史
| 历史视野 | 中华文化 | 中华医药 | 共产党人 |
| -------- | -------- | -------- | -------- |
| lishi | zhonghua | zhongyi | cpers |
争鸣
| 风华正茂 | 工农之声 | 网友杂谈 | 网友时评 |
| -------- | -------- | -------- | -------- |
| qingnian | gongnong | zatan | shiping |
活动
| 乌有公告 | 红色旅游 | 乌有讲堂 | 书画欣赏 |
| -------- | -------- | --------- | -------- |
| gonggao | lvyou | jiangtang | shuhua |
</Route>
## 无产者评论
### 分类

65
lib/v2/wyzxwk/article.js Normal file
View File

@ -0,0 +1,65 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id ?? 'shidai';
const rootUrl = 'http://www.wyzxwk.com';
const currentUrl = `${rootUrl}/Article/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
$('.g-sd').remove();
let items = $('h3 a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.attr('href'),
};
});
items = await Promise.all(
items.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
if (item.link.indexOf('wyzxwk.com') > 0) {
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.zs-modal-body').prev().nextAll().remove();
const pubDate = detailResponse.data.match(/<span class="s-grey-3">(\d{4}-\d{2}-\d{2})<\/span>/);
if (pubDate) {
item.pubDate = parseDate(pubDate[1], 'YYYY-MM-DD');
}
item.description = content('article').html();
} catch (e) {
item.description = '';
}
}
return item;
})
)
);
ctx.state.data = {
title: `${$('title').text().split(' - ')[0]} - 乌有之乡网刊`,
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/article/:id?': ['nczitzk'],
};

13
lib/v2/wyzxwk/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'wyzxwk.com': {
_name: '乌有之乡',
'.': [
{
title: '栏目',
docs: 'https://docs.rsshub.app/new-media.html#wu-you-zhi-xiang-lan-mu',
source: ['/Article/:id', '/'],
target: '/wyzxwk/article/:id?',
},
],
},
};

3
lib/v2/wyzxwk/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/article/:id?', require('./article'));
};