diff --git a/lib/v2/modb/maintainer.js b/lib/v2/modb/maintainer.js new file mode 100644 index 00000000000000..96e307e0fc55f1 --- /dev/null +++ b/lib/v2/modb/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/topic/:id': ['yueneiqi'], +}; diff --git a/lib/v2/modb/radar.js b/lib/v2/modb/radar.js new file mode 100644 index 00000000000000..f8636e83e343d7 --- /dev/null +++ b/lib/v2/modb/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'modb.pro': { + _name: '墨天轮', + '.': [ + { + title: '合辑', + docs: 'https://docs.rsshub.app/routes/programming#mo-tian-lun', + source: ['/', '/topic/:id'], + target: (params) => `/modb/topic/${params.id}`, + }, + ], + }, +}; diff --git a/lib/v2/modb/router.js b/lib/v2/modb/router.js new file mode 100644 index 00000000000000..b7504d0d7d3030 --- /dev/null +++ b/lib/v2/modb/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/topic/:id', require('./topic')); +}; diff --git a/lib/v2/modb/topic.js b/lib/v2/modb/topic.js new file mode 100644 index 00000000000000..7c7bd684e53c57 --- /dev/null +++ b/lib/v2/modb/topic.js @@ -0,0 +1,59 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const logger = require('@/utils/logger'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const baseUrl = 'https://www.modb.pro'; + const topicId = ctx.params.id; + const response = await got({ + url: `${baseUrl}/api/columns/getKnowledge`, + searchParams: { + pageNum: 1, + pageSize: 20, + columnId: topicId, + }, + }).json(); + const list = response.list.map((item) => { + let doc = {}; + let baseLink = {}; + switch (item.type) { + case 0: + doc = item.knowledge; + baseLink = `${baseUrl}/db`; + break; + case 1: + doc = item.dbDoc; + baseLink = `${baseUrl}/doc`; + break; + default: + logger.error(`unknown type ${item.type}`); + } + + return { + title: doc.title, + link: `${baseLink}/${item.rid}`, + pubDate: timezone(parseDate(item.createdTime), +8), + author: doc.createdByName, + category: doc.tags, + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + item.description = $('div.editor-content-styl.article-style').first().html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '墨天轮合辑', + link: `${baseUrl}/topic/${topicId}`, + item: items, + }; +}; diff --git a/website/docs/routes/programming.mdx b/website/docs/routes/programming.mdx index 16ec65bda19f05..2f90b014abf232 100644 --- a/website/docs/routes/programming.mdx +++ b/website/docs/routes/programming.mdx @@ -1398,6 +1398,12 @@ Stay up to date on the latest React news, tutorials, resources, and more. Delive +## 墨天轮 {#mo-tian-lun} + +### 合辑 {#mo-tian-lun-he-ji} + + + ## 平安银河实验室 {#ping-an-yin-he-shi-yan-shi} ### posts {#ping-an-yin-he-shi-yan-shi-posts}