feat: add MCBBS 论坛 (#3294)
This commit is contained in:
parent
7838a0f238
commit
9c9a3cf6ca
10
docs/bbs.md
10
docs/bbs.md
|
|
@ -14,6 +14,16 @@ pageClass: routes
|
|||
|
||||
<Route author="HenryQW" example="/dcard/funny/popular" path="/dcard/:section/:type?" :paramsDesc="['板塊名稱,URL 中獲得', '排序,popular 熱門;latest 最新,默認為 latest']"/>
|
||||
|
||||
## MCBBS
|
||||
|
||||
### 版块
|
||||
|
||||
<Route author="cssxsh" example="/mcbbs/forum/news" path="/mcbbs/forum/:type" :paramsDesc="['版块名称或者版块号']"/>
|
||||
|
||||
### 帖子
|
||||
|
||||
<Route author="cssxsh" example="/mcbbs/post/915861/3038" path="/mcbbs/post/:tid/:authorid?" :paramsDesc="['贴子id,可在帖子 URL 找到', '用户id,此参数不为空时,只看此作者']"/>
|
||||
|
||||
## NGA
|
||||
|
||||
### 分区帖子
|
||||
|
|
|
|||
|
|
@ -1861,6 +1861,10 @@ router.get('/hatena/anonymous_diary/archive', require('./routes/hatena/anonymous
|
|||
// kaggle
|
||||
router.get('/kaggle/discussion/:forumId/:sort?', require('./routes/kaggle/discussion'));
|
||||
|
||||
// mcbbs
|
||||
router.get('/mcbbs/forum/:type', require('./routes/mcbbs/forum'));
|
||||
router.get('/mcbbs/post/:tid/:authorid?', require('./routes/mcbbs/post'));
|
||||
|
||||
// Pocket
|
||||
router.get('/pocket/trending', require('./routes/pocket/trending'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
|
||||
const response = await got(utils.forumUrl, {
|
||||
method: 'get',
|
||||
params: {
|
||||
mod: 'forumdisplay',
|
||||
fid: type,
|
||||
// 最新帖子
|
||||
filter: 'lastpost',
|
||||
orderby: 'lastpost',
|
||||
},
|
||||
baseUrl: utils.host,
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const title = $('title').text();
|
||||
const list = $('#separatorline ~ tbody');
|
||||
const description = $('meta[name="description"]').attr('content');
|
||||
const item = list
|
||||
.map((index, element) => {
|
||||
const title = $('.s', element).text();
|
||||
const href = $('.icn > a', element).attr('href');
|
||||
const link = `${utils.host}/${href}`;
|
||||
const postBy = $('.by', element);
|
||||
const author = $('cite', postBy[0]);
|
||||
const postDate = $('span[title]', postBy[0]);
|
||||
const endAuthor = $('cite', postBy[1]);
|
||||
const endDate = $('span[title]', postBy[1]);
|
||||
const description = `${author.html()}发表于${postDate.parent().html()},最后由${endAuthor.html()}于${endDate.parent().html()}回复。`;
|
||||
const pubDate = new Date(`${endDate.attr('title')} GMT+0800`).toUTCString();
|
||||
const category = $('.new > em', element).text();
|
||||
|
||||
const signle = {
|
||||
title: title,
|
||||
link: link,
|
||||
author: author.text(),
|
||||
description: description,
|
||||
pubDate: pubDate,
|
||||
category: category,
|
||||
};
|
||||
return signle;
|
||||
})
|
||||
.get();
|
||||
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: response.url,
|
||||
description: description,
|
||||
allowEmpty: true,
|
||||
item: item,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const tid = ctx.params.tid;
|
||||
const authorid = ctx.params.authorid;
|
||||
const response = await got(utils.forumUrl, {
|
||||
method: 'get',
|
||||
params: {
|
||||
mod: 'viewthread',
|
||||
tid: tid,
|
||||
authorid: authorid,
|
||||
// 倒序查看帖子
|
||||
ordertype: 1,
|
||||
},
|
||||
baseUrl: utils.host,
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const title = $('title').text();
|
||||
const description = $('meta[name="description"]').attr('content');
|
||||
// const description = $('div[id^=post_] > .t_f').html();
|
||||
const postPan = authorid ? $('#postlist > div[id^=post_]') : $('#postlist > div[id^=post_]').nextAll();
|
||||
const item = postPan
|
||||
.map((index, element) => {
|
||||
const link = utils.host + '/' + $('[id^=postnum]', element).attr('href');
|
||||
const xw1 = $('.authi > .xw1', element);
|
||||
const author = xw1.text();
|
||||
const description = $('.t_f', element).html();
|
||||
const em = $('[id^=authorposton]', element);
|
||||
const date = em.text();
|
||||
const span = $('span', em);
|
||||
const postDate = span ? span.attr('title') : date;
|
||||
const title = `${xw1.html()} ${em.html()}`;
|
||||
const pubDate = new Date(`${postDate} GMT+0800`).toUTCString();
|
||||
|
||||
const signle = {
|
||||
title: title,
|
||||
link: link,
|
||||
author: author,
|
||||
description: description,
|
||||
pubDate: pubDate,
|
||||
};
|
||||
return signle;
|
||||
})
|
||||
.get();
|
||||
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: response.url,
|
||||
description: description,
|
||||
allowEmpty: true,
|
||||
item: item,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
const utils = {
|
||||
host: 'https://www.mcbbs.net',
|
||||
forumUrl: '/forum.php',
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
Loading…
Reference in New Issue