diff --git a/docs/bbs.md b/docs/bbs.md index e9d3c0d9f..2f27dee6a 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -208,6 +208,32 @@ pageClass: routes +## Mobilism + +### 论坛 + + + +| 安卓 | iPhone | iPad | +| ------- | ------ | ---- | +| android | iphone | ipad | + +| 应用 | 游戏 | +| ---- | ----- | +| apps | games | + + + +### 门户 + + + +| 安卓应用 | 安卓游戏 | 图书 | iPad 应用 | iPad 游戏 | iPhone 应用 | iPhone 游戏 | +| ---- | ----- | ----- | ------- | ------- | --------- | --------- | +| aapp | agame | ebook | ipapp | ipgame | iapp | igame | + + + ## NGA ### 分区帖子 diff --git a/docs/en/bbs.md b/docs/en/bbs.md index bce33ca47..eb86832bb 100644 --- a/docs/en/bbs.md +++ b/docs/en/bbs.md @@ -36,6 +36,32 @@ pageClass: routes +## Mobilism + +### Forums + + + +| Android | iPhone | iPad | +| ------- | ------ | ---- | +| android | iphone | ipad | + +| Apps | games | +| ---- | ----- | +| apps | games | + + + +### Portal + + + +| Android Apps | Android Games | ebook | iPad Apps | iPad Games | iPhone Apps | iPhone Games | +| ------------ | ------------- | ----- | --------- | ---------- | ----------- | ------------ | +| aapp | agame | ebook | ipapp | ipgame | iapp | igame | + + + ## SCBOY forum ### Thread diff --git a/docs/en/reading.md b/docs/en/reading.md index 09f23fc0d..7ebac82ba 100644 --- a/docs/en/reading.md +++ b/docs/en/reading.md @@ -38,7 +38,24 @@ Eg: ### Category - + + +## Mobilism + +### eBook Releases + + + +| Category | Parameter | +| ------------------------ | ---------- | +| Romance | romance | +| Sci-Fi/Fantasy/Horror | scifi | +| General Fiction/Classics | classics | +| Magazines & Newspapers | magazines | +| Audiobooks | audioBooks | +| Comics | comics | + + ## syosetu diff --git a/docs/reading.md b/docs/reading.md index 780a1fb33..f54ce36f8 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -54,9 +54,20 @@ pageClass: routes ## Mobilism -### eBook Releases +### 电子书 - + + +| 分类名 | 参数 | +| -------- | ---------- | +| 浪漫 | romance | +| 科幻、幻想、恐怖 | scifi | +| 普通小说、经典 | classics | +| 杂志、报纸 | magazines | +| 有声读物 | audioBooks | +| 漫画 | comics | + + ## SoBooks diff --git a/lib/router.js b/lib/router.js index 63bc62c47..73b69ab26 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2862,9 +2862,6 @@ router.get('/law/dh', lazyloadRouteHandler('./routes/law/dh')); // 金诚同达律师事务所文章 router.get('/law/jctd', lazyloadRouteHandler('./routes/law/jctd')); -// Mobilism -router.get('/mobilism/release', lazyloadRouteHandler('./routes/mobilism/release')); - // 三星盖乐世社区 router.get('/samsungmembers/latest', lazyloadRouteHandler('./routes/samsungmembers/latest')); diff --git a/lib/routes/mobilism/release.js b/lib/routes/mobilism/release.js deleted file mode 100644 index 84939058d..000000000 --- a/lib/routes/mobilism/release.js +++ /dev/null @@ -1,42 +0,0 @@ -const url = require('url'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const currentUrl = `https://forum.mobilism.org/viewforum.php?f=19`; - const response = await got({ - method: 'get', - url: currentUrl, - }); - const $ = cheerio.load(response.data); - const list = $('tbody') - .eq(1) - .find('tr') - .map((_, item) => { - item = $(item); - const a = item.find('a'); - return { - title: a.text(), - link: url.resolve(`https://forum.mobilism.org`, a.attr('href')), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const res = await got({ method: 'get', url: item.link }); - const content = cheerio.load(res.data); - - item.description = content('div.content').html(); - return item; - }) - ) - ); - - ctx.state.data = { - title: 'Mobilism - eBook Releases', - link: currentUrl, - item: items, - }; -}; diff --git a/lib/v2/mobilism/forums.js b/lib/v2/mobilism/forums.js new file mode 100644 index 000000000..a7e7ed450 --- /dev/null +++ b/lib/v2/mobilism/forums.js @@ -0,0 +1,75 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { toTitleCase } = require('@/utils/common-utils'); +const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); +const rootUrl = `https://forum.mobilism.org/viewforum.php?f=`; +const categeoryMap = { + books: { + romance: 1292, + scifi: 1293, + classics: 121, + magazines: 123, + audioBooks: 124, + comics: 311, + }, + android: { + apps: 399, + games: 408, + }, + iphone: { + apps: 316, + games: 320, + }, + ipad: { + apps: 951, + games: 988, + }, +}; +module.exports = async (ctx) => { + const { category, type, fulltext } = ctx.params; + const currentUrl = rootUrl + categeoryMap[category][type]; + const response = await got(currentUrl); + const $ = cheerio.load(cheerio.load(response.data)('tbody')[1]); + const lists = $('tbody > tr'); + const list = lists + .map((index, item) => { + item = $(item); + const title = item.find('td').first().find('a[title]').text(); + const link = new URL(item.find('td').first().find('a[title]').attr('href'), 'https://forum.mobilism.org'); + const author = item.find('td').first().find('a.username-coloured').text(); + const pubDate = item.find('td').first().find('small').text(); + link.searchParams.delete('sid'); + return { + title, + link: link.toString(), + author, + pubDate: /ago|day/.test(pubDate) ? parseRelativeDate(pubDate) : parseDate(pubDate, 'MMM D, YYYY, h:mm a'), + }; + }) + .get() + .sort((a, b) => b.pubDate - a.pubDate) + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 35); + // server will return 520 if concurrency > 37 when fulltext is used + let items; + if (fulltext === 'y') { + items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + item.description = content('div.content').html(); + return item; + }) + ) + ); + } else { + items = list; + } + + ctx.state.data = { + title: `Mobilism Forums ${toTitleCase(category)} ${toTitleCase(type)} Release`, + link: currentUrl, + description: `Mobilism Forums ${toTitleCase(category)} ${toTitleCase(type)} RSS`, + item: items, + }; +}; diff --git a/lib/v2/mobilism/maintainer.js b/lib/v2/mobilism/maintainer.js new file mode 100644 index 000000000..23853f51f --- /dev/null +++ b/lib/v2/mobilism/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/forums/:category/:type/:fulltext?': ['nitezs'], + '/portal/:type/:fulltext?': ['nitezs'], +}; diff --git a/lib/v2/mobilism/portal.js b/lib/v2/mobilism/portal.js new file mode 100644 index 000000000..f61cd83a3 --- /dev/null +++ b/lib/v2/mobilism/portal.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { toTitleCase } = require('@/utils/common-utils'); +const { parseDate, parseRelativeDate } = require('@/utils/parse-date'); + +const get = (data) => { + const $ = cheerio.load(data); + const posts = $('div.span9 > section'); + const items = posts + .map((index, item) => { + item = $(item); + const link = new URL(item.find('div.well > a').attr('href'), 'https://forum.mobilism.org'); + const pubDate = item.find('div.well > span.muted > em').text().replace(item.find('div.well > span.muted > em > strong').text(), '').replace(' at ', '').split(' in ')[0]; + link.searchParams.delete('sid'); + return { + title: item.find('div.page-header > h3').text(), + link: link.toString(), + author: item.find('div.well > span.muted > em > strong').text().replace('Posted by: ', ''), + description: item.find('div.well > div.postbody').text(), + pubDate: /ago|day/.test(pubDate) ? parseRelativeDate(pubDate) : parseDate(pubDate, 'MMM D, YYYY, h:mm a'), + }; + }) + .get(); + return items; +}; + +module.exports = async (ctx) => { + const { type, fulltext } = ctx.params; + const url = `https://forum.mobilism.org/portal.php?mode=articles&block=${type}&sk=t&sd=d&start=0`; + const response = await got(url); + const list = get(response.data); + let items; + if (fulltext === 'y') { + items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + item.description = content('div.content').html(); + return item; + }) + ) + ); + } else { + items = list; + } + + ctx.state.data = { + title: `Mobilism Portal ${toTitleCase(type)} Release`, + link: url, + description: `Mobilism Portal ${toTitleCase(type)} RSS`, + item: items, + }; +}; diff --git a/lib/v2/mobilism/radar.js b/lib/v2/mobilism/radar.js new file mode 100644 index 000000000..1ac08d619 --- /dev/null +++ b/lib/v2/mobilism/radar.js @@ -0,0 +1,23 @@ +module.exports = { + 'mobilism.org': { + _name: 'Mobilism', + '.': [ + { + title: '论坛', + docs: 'https://docs.rsshub.app/bbs.html#mobilism', + source: '/', + }, + { + title: '门户', + docs: 'https://docs.rsshub.app/bbs.html#mobilism', + source: '/portal.php', + target: (_params, url) => `/mobilism/portal/${new URL(url).searchParams.get('block')}`, + }, + { + title: '电子书', + docs: 'https://docs.rsshub.app/reading.html#mobilism', + source: '/', + }, + ], + }, +}; diff --git a/lib/v2/mobilism/router.js b/lib/v2/mobilism/router.js new file mode 100644 index 000000000..0d4647855 --- /dev/null +++ b/lib/v2/mobilism/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/forums/:category/:type/:fulltext?', require('./forums')); + router.get('/portal/:type/:fulltext?', require('./portal')); +};