fix(route): 36kr主题文章 (#10161)

* fix(route): 36kr主题文章

* fix: add fulltext
This commit is contained in:
Ethan Shen
2022-07-07 21:25:31 +08:00
committed by GitHub
parent 3b7daf432e
commit 32b0ce9058
4 changed files with 46 additions and 25 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ pageClass: routes
### 主题文章
<Route author="nczitzk" example="/36kr/motif/452" path="/36kr/motif/:mid" :paramsDesc="['主题 ID']" />
<Route author="nczitzk" example="/36kr/motif/452" path="/36kr/motif/:id" :paramsDesc="['主题 ID']" />
### 搜索文章
+2 -2
View File
@@ -1,7 +1,7 @@
module.exports = {
'/motif/:mid': ['nczitzk'],
'/motif/:id': ['nczitzk'],
'/news/:category?': ['nczitzk'],
'/newsflashes': ['hillerliao'],
'/search/article/:keyword': ['xyqfer', 'kt286', 'nczitzk'],
'/user/:uid': ['nczitzk'],
'/user/:id': ['nczitzk'],
};
+42 -21
View File
@@ -1,36 +1,57 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const CryptoJS = require('crypto-js');
module.exports = async (ctx) => {
const motifUrl = `https://36kr.com/motif/${ctx.params.mid}`;
const id = ctx.params.id;
const rootUrl = 'https://36kr.com';
const currentUrl = `${rootUrl}/motif/${id}`;
const response = await got({
method: 'get',
url: motifUrl,
url: currentUrl,
});
const data = JSON.parse(response.data.match(/"motifDetailData":{"code":0,"data":(.*?)},"channel":/)[1]);
const motifInfo = data.motifInfo.data;
const motifArticleList = data.motifArticleList.data.itemList;
const articleList = motifArticleList.map((item) => ({
const data = JSON.parse(response.data.match(/"motifDetailData":{"code":0,"data":(.*)},"channel"/)[1]);
let items = data.motifArticleList.data.itemList.map((item) => ({
title: item.templateMaterial.widgetTitle,
link: `https://36kr.com/${item.route.split('?')[0] === 'detail_video' ? 'video' : 'p'}/${item.itemId}`,
link: `${rootUrl}/p/${item.itemId}`,
pubDate: parseDate(item.templateMaterial.publishTime),
}));
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const key = CryptoJS.enc.Utf8.parse('efabccee-b754-4c');
const cipherText = detailResponse.data.match(/{"state":"(.*)","isEncrypt":true}/)[1];
const content = JSON.parse(
CryptoJS.AES.decrypt(cipherText, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})
.toString(CryptoJS.enc.Utf8)
.toString()
).articleDetail.articleDetailData.data;
item.author = content.author;
item.description = content.widgetContent;
return item;
})
)
);
ctx.state.data = {
title: `36氪专题 - ${motifInfo.categoryTitle}`,
link: motifUrl,
item: await Promise.all(
articleList.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const contentResponse = await got({ method: 'get', url: item.link });
const result = contentResponse.data.match(/"articleDetailData":(.*?),"articleRecommendData":/) || contentResponse.data.match(/"videoDetail":(.*?),"authorVideos":/);
const contentData = JSON.parse(result[1]);
item.description = contentData.data.widgetContent;
return item;
})
)
),
description: motifInfo.categoryTitle,
title: `36kr - ${data.motifInfo.data.categoryTitle}`,
link: currentUrl,
item: items,
};
};
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = (router) => {
router.get('/motif/:mid', require('./motif'));
router.get('/motif/:id', require('./motif'));
router.get('/news/:category?', require('./news'));
router.get('/newsflashes', require('./newsflashes'));
router.get('/search/article/:keyword', require('./search/article'));