feat: 添加微信公众号文章话题 Tag (#5639)

This commit is contained in:
MisteryMonster
2020-09-21 04:01:59 +08:00
committed by GitHub
parent 221d8139fa
commit bccc5ebc22
4 changed files with 74 additions and 0 deletions

View File

@@ -1829,6 +1829,12 @@
source: '/mp/homepage', source: '/mp/homepage',
target: (params, url) => `/wechat/mp/homepage/${new URL(url).searchParams.get('__biz')}/${new URL(url).searchParams.get('hid')}/${new URL(url).searchParams.get('cid') ? new URL(url).searchParams.get('cid') : ''}`, target: (params, url) => `/wechat/mp/homepage/${new URL(url).searchParams.get('__biz')}/${new URL(url).searchParams.get('hid')}/${new URL(url).searchParams.get('cid') ? new URL(url).searchParams.get('cid') : ''}`,
}, },
{
title: '微信公众号话题',
docs: 'https://docs.rsshub.app/new-media.html#wei-xin-gong-zhong-hao-wen-zhang-hua-ti-tag',
source: '/mp/appmsgalbum',
target: (params, url) => `/wechat/mp/msgalbum/${new URL(url).searchParams.get('__biz')}/${new URL(url).searchParams.get('album_id')}`,
},
], ],
egame: [ egame: [
{ {

View File

@@ -1271,6 +1271,14 @@ area 分区选项
</Route> </Route>
### 公众号文章话题 Tag
<Route author="MisteryMonster" example="/wechat/mp/msgalbum/MzA3MDM3NjE5NQ==/1375870284640911361" path="/wechat/mp/msgalbum/:biz/:aid" :paramsDesc="['公众号id', 'Tag id', ]" radar="1" anticrawler="1">
一些公众号(如看理想)会在微信文章里添加 Tag ,点入 Tag 的链接如 <https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzA3MDM3NjE5NQ==&action=getalbum&album_id=1375870284640911361>,其中`biz``MzA3MDM3NjE5NQ==``aid``1375870284640911361`
</Route>
### 公众平台系统公告栏目 ### 公众平台系统公告栏目
<Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" /> <Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" />

View File

@@ -502,6 +502,7 @@ router.get('/wechat/uread/:userid', require('./routes/tencent/wechat/uread'));
router.get('/wechat/ershicimi/:id', require('./routes/tencent/wechat/ershcimi')); router.get('/wechat/ershicimi/:id', require('./routes/tencent/wechat/ershcimi'));
router.get('/wechat/wjdn/:id', require('./routes/tencent/wechat/wjdn')); router.get('/wechat/wjdn/:id', require('./routes/tencent/wechat/wjdn'));
router.get('/wechat/mp/homepage/:biz/:hid/:cid?', require('./routes/tencent/wechat/mp')); router.get('/wechat/mp/homepage/:biz/:hid/:cid?', require('./routes/tencent/wechat/mp'));
router.get('/wechat/mp/msgalbum/:biz/:aid', require('./routes/tencent/wechat/msgalbum'));
// All the Flight Deals // All the Flight Deals
router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index')); router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));

View File

@@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const dayjs = require('dayjs');
module.exports = async (ctx) => {
const { biz, aid } = ctx.params;
const aidurl = `&album_id=${aid}`;
const HTMLresponse = await got({
method: 'get',
url: `https://mp.weixin.qq.com/mp/appmsgalbum?__biz=${biz}&action=getalbum${aidurl}`,
});
const $ = cheerio.load(HTMLresponse.data);
const list = $('li').get();
const mptitle = $('.album__author-name').text() + `|` + $('.album__label-title').text();
const articledata = await Promise.all(
list.map(async (item) => {
const link = $(item).attr('data-link').replace('http://', 'https://');
const title = $(item).attr('data-title');
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response2 = await got({
method: 'get',
url: link,
});
const articleHtml = response2.data;
const $2 = cheerio.load(articleHtml);
$2('img').removeAttr('src');
$2('div#js_profile_qrcode').remove();
const content = $2('div#js_content.rich_media_content')
.html()
.replace('iframe/preview.html?width=500&amp;height=375&amp;', 'txp/iframe/player.html?')
.replace('<iframe ', '<iframe width="640" height="360"')
.replace(/data-src/g, 'src');
const author = $2('div#meta_content:not(:last-child)').text();
const single = {
content,
author,
link,
title,
};
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${mptitle}`,
link: `https://mp.weixin.qq.com/mp/appmsgalbum?__biz=${biz}&action=getalbum${aidurl}`,
item: list.map((item, index) => ({
title: `${articledata[index].title}`,
description: $(item).find('.album__item-img').html() + `<br><br>${articledata[index].content}`,
link: `${articledata[index].link}`,
author: `${articledata[index].author}`,
pubDate: dayjs.unix($(item).find('.js_article_create_time').text()).format(),
})),
};
};