diff --git a/docs/study.md b/docs/study.md index 3926807c07..1edf9faf52 100644 --- a/docs/study.md +++ b/docs/study.md @@ -170,6 +170,10 @@ pageClass: routes +## 幕布精选 + + + ## 扇贝 ### 用户打卡 diff --git a/lib/router.js b/lib/router.js index 284e61a14b..11c6bbec2a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3512,6 +3512,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news')); router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt')); router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic')); +// 幕布网 +router.get('/mubu/explore/:tagId/:title?', require('./routes/mubu/explore')); + // Esquirehk router.get('/esquirehk/tag/:id', require('./routes/esquirehk/tag')); diff --git a/lib/routes/mubu/explore.js b/lib/routes/mubu/explore.js new file mode 100644 index 0000000000..d699d98c74 --- /dev/null +++ b/lib/routes/mubu/explore.js @@ -0,0 +1,80 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const tagId = ctx.params.tagId; + const title = ctx.params.title || ''; + + const response = await got({ + method: 'post', + url: `https:mubu.com/api/community/query_document`, + form: { + page: 1, + tagId, + title: '', + type: '', + docRecommend: '', + }, + headers: { + referer: 'https:mubu.com/explore', + }, + }); + + const h = (nodes) => { + const list = nodes + .map((node) => { + let ele = ''; + if (Array.isArray(node.children)) { + ele = h(node.children); + } + if (Array.isArray(node.images)) { + ele += node.images + .map((pic) => `https://api2.mubu.com/v3/${pic.uri}`) + .map((uri) => `
`) + .join(''); + } + + return `
  • ${node.text}${ele}
  • `; + }) + .join(''); + + return ``; + }; + + const item = await Promise.all( + response.data.data.rows.slice(0, 20).map((item) => + ctx.cache.tryGet(`https://mubu.com/doc/explore/${item.id}`, async () => { + const res = await got({ + method: 'post', + url: `https://api2.mubu.com/v3/api/document/view/get`, + json: { + docId: item.documentId, + }, + headers: { + referer: 'https://mubu.com/', + }, + }); + const content = JSON.parse(res.data.data.definition); + const description = h(content.nodes); + + const $ = cheerio.load(description); + $('.bold').css('font-weight', 'bold'); + $('.text-color-red').css('color', '#dc2d1e'); + + return { + title: item.title, + link: `https://mubu.com/doc/explore/${item.id}`, + description: `

    ${item.title}

    ` + $('*').html(), + pubDate: new Date(item.publishTime), + author: item.userName, + }; + }) + ) + ); + + ctx.state.data = { + title: title ? `幕布 - ${title}` : '幕布', + link: `https://mubu.com/explore#${tagId}`, + item, + }; +};