feat: add 梅花网文章与作品 (#5208)

This commit is contained in:
Ethan Shen
2020-07-29 14:29:16 +01:00
committed by GitHub
parent e7d62ebcd9
commit a4bed8741b
4 changed files with 140 additions and 0 deletions
+22
View File
@@ -753,6 +753,28 @@ area 分区选项
<Route author="xyqfer" example="/laosiji/hotshow/128" path="/laosiji/hotshow/:id" :paramsDesc="['节目 id']"/>
## 梅花网
### 作品
<Route author="nczitzk" example="/meihua/shots/latest" path="/meihua/shots/:caty">
| 最新 | 热门 | 推荐 |
| ------ | ---- | --------- |
| latest | hot | recommend |
</Route>
### 文章
<Route author="nczitzk" example="/meihua/article/latest" path="/meihua/article/:caty">
| 最新 | 热门 |
| ------ | ---- |
| latest | hot |
</Route>
## 镁客网 im2maker
### 镁客网频道
+4
View File
@@ -2980,6 +2980,10 @@ router.get('/12379', require('./routes/12379/index'));
router.get('/ngbj/today', require('./routes/niaogebiji/today'));
router.get('/ngbj/cat/:cat', require('./routes/niaogebiji/cat'));
// 梅花网
router.get('/meihua/shots/:caty', require('./routes/meihua/shots'));
router.get('/meihua/article/:caty', require('./routes/meihua/article'));
// 看点快报
router.get('/kuaibao', require('./routes/kuaibao/index'));
+55
View File
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const config = {
latest: {
link: 'article!2',
title: '最新',
},
hot: {
link: 'article!3',
title: '热门',
},
};
module.exports = async (ctx) => {
const cfg = config[ctx.params.caty];
if (!cfg) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/new-media.html#mei-hua-wang-wen-zhang">docs</a>');
}
const currentUrl = `https://www.meihua.info/${cfg.link}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const data = JSON.parse(response.data.match(/"compositionStore":(.*?),"detailStore":/)[1]);
const shotList = data.compositionsData.list.map((item) => ({
title: item.title,
link: `https://www.meihua.info/article/${item.compositionId}`,
pubDate: new Date(item.gmtPublish).toUTCString(),
}));
const items = await Promise.all(
shotList.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const contentResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(contentResponse.data);
item.description = content('#article-content-html').html();
return item;
})
)
);
ctx.state.data = {
title: `${cfg.title}文章 - 梅花网`,
link: currentUrl,
item: items,
};
};
+59
View File
@@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const config = {
recommend: {
link: 'shots!1!0!0!0!0',
title: '推荐',
},
latest: {
link: 'shots!2!0!0!0!0',
title: '最新',
},
hot: {
link: 'shots!3!0!0!0!0',
title: '热门',
},
};
module.exports = async (ctx) => {
const cfg = config[ctx.params.caty];
if (!cfg) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/new-media.html#mei-hua-wang-zuo-pin">docs</a>');
}
const currentUrl = `https://www.meihua.info/${cfg.link}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const data = JSON.parse(response.data.match(/"shotsStore":(.*?),"commentStore":/)[1]);
const shotList = data.shotsData.list.map((item) => ({
title: item.title,
link: `https://www.meihua.info/shots/${item.compositionId}`,
pubDate: new Date(item.gmtPublish).toUTCString(),
}));
const items = await Promise.all(
shotList.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const contentResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(contentResponse.data);
item.description = content('div.summary').html();
return item;
})
)
);
ctx.state.data = {
title: `${cfg.title}作品 - 梅花网`,
link: currentUrl,
item: items,
};
};