fix(route): 幕布精选社区 (#7690)

This commit is contained in:
Ethan Shen
2021-06-19 23:49:54 -04:00
committed by GitHub
parent c74e6ff6e8
commit d84bb8473e
3 changed files with 28 additions and 30 deletions
+1 -1
View File
@@ -246,7 +246,7 @@ pageClass: routes
## 幕布精选
<Route author="laampui" example="/mubu/explore/16/读书笔记" path="/mubu/explore/:tagId/:title?" :paramsDesc="['标签 id', '显示标题']" />
<Route author="laampui nczitzk" example="/mubu/explore/16/读书笔记" path="/mubu/explore/:category?/:title?" :paramsDesc="['分类 id', '显示标题']" />
## 扇贝
+1 -1
View File
@@ -3686,7 +3686,7 @@ router.get('/mind42/search/:keyword', require('./routes/mind42/search'));
router.get('/mind42/:caty?', require('./routes/mind42/index'));
// 幕布网
router.get('/mubu/explore/:tagId/:title?', require('./routes/mubu/explore'));
router.get('/mubu/explore/:category?/:title?', require('./routes/mubu/explore'));
// Esquirehk
router.get('/esquirehk/tag/:id', require('./routes/esquirehk/tag'));
+26 -28
View File
@@ -2,21 +2,22 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const tagId = ctx.params.tagId;
const title = ctx.params.title || '';
const category = ctx.params.category || '0';
const rootUrl = 'https://mubu.com';
const apiUrl = 'https://api2.mubu.com';
const exploreUrl = `${apiUrl}/v3/api/explore/get_explore_doc_list`;
const documentUrl = `${apiUrl}/v3/api/explore/get`;
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',
url: exploreUrl,
json: {
categoryId: '3',
pageSize: '20',
start: '',
type: category === '0' ? 0 : 1,
},
});
@@ -29,8 +30,8 @@ module.exports = async (ctx) => {
}
if (Array.isArray(node.images)) {
ele += node.images
.map((pic) => `https://api2.mubu.com/v3/${pic.uri}`)
.map((uri) => `<div style="text-align: center;"><img src="${uri}" style="max-width: 100%;object-fit: contain;" /></div>`)
.map((pic) => `${apiUrl}/v3/${pic.url}`)
.map((url) => `<div style="text-align: center;"><img src="${url}" style="max-width: 100%;object-fit: contain;" /></div>`)
.join('');
}
@@ -41,20 +42,17 @@ module.exports = async (ctx) => {
return `<ul>${list}</ul>`;
};
const item = await Promise.all(
const items = 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({
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'post',
url: `https://api2.mubu.com/v3/api/document/view/get`,
url: documentUrl,
json: {
docId: item.documentId,
},
headers: {
referer: 'https://mubu.com/',
exploreDocId: item.exploreDocId,
},
});
const content = JSON.parse(res.data.data.definition);
const content = JSON.parse(detailResponse.data.data.definition);
const description = h(content.nodes);
const $ = cheerio.load(description);
@@ -63,18 +61,18 @@ module.exports = async (ctx) => {
return {
title: item.title,
link: `https://mubu.com/doc/explore/${item.id}`,
description: `<h2>${item.title}</h2>` + $('*').html(),
pubDate: new Date(item.publishTime),
author: item.userName,
pubDate: new Date(item.submitTime),
link: `${rootUrl}/explore/${item.exploreDocId}`,
description: `<h2>${item.title}</h2>` + $('*').html(),
};
})
)
);
ctx.state.data = {
title: title ? `幕布 - ${title}` : '幕布',
link: `https://mubu.com/explore#${tagId}`,
item,
title: `${title ? `${title} - ` : ''}幕布精选社区`,
link: `${rootUrl}/explore?categoryId=${category}`,
item: items,
};
};