feat: add LearnKu 论坛 (#4197)
This commit is contained in:
parent
f6fca3483a
commit
46d1052e8a
10
docs/bbs.md
10
docs/bbs.md
|
|
@ -40,6 +40,16 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## LearnKu
|
||||
|
||||
### 社区
|
||||
|
||||
<Route author="haokaiyang" example="/learnku/laravel/qa" path="/learnku/:community/:category?" :paramsDesc="['社区 标识,可在 <https://learnku.com/communities> 找到', '分类,如果不传 `category` 则获取全部分类']"/>
|
||||
|
||||
| 招聘 | 翻译 | 问答 | 链接 |
|
||||
| ---- | ------------ | ---- | ----- |
|
||||
| jobs | translations | qa | links |
|
||||
|
||||
## MCBBS
|
||||
|
||||
### 版块
|
||||
|
|
|
|||
|
|
@ -2346,4 +2346,7 @@ router.get('/guat/news/:type?', require('./routes/guat/news'));
|
|||
// 国家留学网
|
||||
router.get('/csc/notice/:type?', require('./routes/csc/notice'));
|
||||
|
||||
// LearnKu
|
||||
router.get('/learnku/:community/:category?', require('./routes/learnku/topic'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const community = ctx.params.community;
|
||||
const category = ctx.params.category || '';
|
||||
|
||||
let url = `https://learnku.com/${community}`;
|
||||
if (category !== '') {
|
||||
url = `https://learnku.com/${community}/c/${category}`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('.simple-topic').get();
|
||||
const title = $('.sidebar .community-details .header span').text();
|
||||
$('.sidebar .community-details .main div div a').remove();
|
||||
const description = $('.sidebar .community-details .main div div').text();
|
||||
const categoryTitle = new Map([
|
||||
['translations', { name: '翻译' }],
|
||||
['jobs', { name: '招聘' }],
|
||||
['qa', { name: '问答' }],
|
||||
['links', { name: '链接' }],
|
||||
['', { name: '最新' }],
|
||||
]);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `LearnKu - ${title} - ${categoryTitle.get(category).name}`,
|
||||
link: url,
|
||||
description: description,
|
||||
item: list
|
||||
.map((item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const categoryName = $('.category-name')
|
||||
.text()
|
||||
.trim();
|
||||
if (['置顶', '广告'].includes(categoryName)) {
|
||||
return '';
|
||||
}
|
||||
$('.topic-title i').remove();
|
||||
return {
|
||||
title: $('.topic-title')
|
||||
.text()
|
||||
.trim(),
|
||||
category: categoryName,
|
||||
link: $('.topic-title-wrap').attr('href'),
|
||||
pubDate: new Date($('.timeago').attr('title')).toUTCString(),
|
||||
};
|
||||
})
|
||||
.filter((item) => item !== ''),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue