feat(route): add 集思录用户回复 & 主题 (#7168)

* feat: add 集思录用户回复 & 主题

* add docs

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen 2021-03-14 14:35:11 +08:00 committed by GitHub
parent cacf988b2c
commit 8e949ec548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 147 additions and 0 deletions

View File

@ -322,6 +322,16 @@ pageClass: routes
</Route>
## 集思录
### 用户回复
<Route author="nczitzk" example="/jisilu/reply/BKL" path="/jisilu/reply/:user" :paramsDesc="['用户名,可在用户页 URL 中找到']"/>
### 用户主题
<Route author="nczitzk" example="/jisilu/topic/BKL" path="/jisilu/reply/:topic" :paramsDesc="['用户名,可在用户页 URL 中找到']"/>
## 看雪
### 论坛

View File

@ -4042,6 +4042,10 @@ router.get('/wainao-reads/all-articles', require('./routes/wainao/index'));
// react
router.get('/react/react-native-weekly', require('./routes/react/react-native-weekly'));
// 集思录
router.get('/jisilu/reply/:user', require('./routes/jisilu/reply'));
router.get('/jisilu/topic/:user', require('./routes/jisilu/topic'));
// Constitutional Court of Baden-Württemberg (Germany)
router.get('/verfghbw/press/:keyword?', require('./routes/verfghbw/press'));

View File

@ -0,0 +1,64 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const user = ctx.params.user;
const rootUrl = 'https://www.jisilu.cn';
const currentUrl = `${rootUrl}/people/${user}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const id = response.data.match(/var PEOPLE_USER_ID = '(.*)'/)[1];
const name = response.data.match(/<title>(.*) 的个人主页 - 集思录<\/title>/)[1];
const apiUrl = `${rootUrl}/people/ajax/user_actions/uid-${id}__actions-201__page-0`;
const apiResponse = await got({
method: 'get',
url: apiUrl,
});
const $ = cheerio.load(apiResponse.data);
const list = $('.aw-item')
.slice(0, 15)
.map((_, item) => {
item = $(item);
const a = item.find('.aw-hide-txt a');
return {
author: name,
title: a.text(),
link: a.attr('href'),
pubDate: new Date(item.find('.aw-text-color-999').text()).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.aw-dynamic-topic-more-operate').remove();
item.description = content('.aw-dynamic-topic-content').html();
return item;
})
)
);
ctx.state.data = {
title: `${name}的回复 - 集思录`,
link: currentUrl,
item: items,
};
};

View File

@ -0,0 +1,69 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const user = ctx.params.user;
const rootUrl = 'https://www.jisilu.cn';
const currentUrl = `${rootUrl}/people/${user}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const id = response.data.match(/var PEOPLE_USER_ID = '(.*)'/)[1];
const name = response.data.match(/<title>(.*) 的个人主页 - 集思录<\/title>/)[1];
const apiUrl = `${rootUrl}/people/ajax/user_actions/uid-${id}__actions-101__page-0`;
const apiResponse = await got({
method: 'get',
url: apiUrl,
});
const $ = cheerio.load(apiResponse.data);
const list = $('.aw-item')
.slice(0, 15)
.map((_, item) => {
item = $(item);
const a = item.find('.aw-hide-txt a');
return {
author: name,
title: a.text(),
link: a.attr('href'),
pubDate: new Date(
item
.find('.aw-text-color-999')
.text()
.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)[0]
).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.aw-dynamic-topic-more-operate').remove();
item.description = content('.aw-question-detail-txt').html();
return item;
})
)
);
ctx.state.data = {
title: `${name}的主题 - 集思录`,
link: currentUrl,
item: items,
};
};