feat: add wxnmh.com #5324 (#6063)

This commit is contained in:
Laam Pui
2020-11-03 11:28:36 +00:00
committed by GitHub
parent 900fbe83dd
commit 237625808d
3 changed files with 52 additions and 0 deletions
+4
View File
@@ -1453,6 +1453,10 @@ column 为 third 时可选的 category:
<Route author="BugWriter2" example="/wechat/wjdn/5d5e683c82339df472988f59" path="/wechat/wjdn/:id" :paramsDesc="['公众号 id, 打开公众号页, 在 URL 中找到 id']"/>
### 公众号 (wxnmh.com 来源)
<Route author="laampui" example="/wechat/wxnmh/51798" path="/wechat/wxnmh/:id" :paramsDesc="['公众号 id, 打开 wxnmh.com, 在 URL 中找到 id']"/>
### 公众号栏目 (非推送 & 历史消息)
<Route author="MisteryMonster" example="/wechat/mp/homepage/MzA3MDM3NjE5NQ==/16" path="/wechat/mp/homepage/:biz/:hid/:cid?" :paramsDesc="['公众号id', '分页id', '页内栏目']" radar="1" rssbud="1" anticrawler="1">
+1
View File
@@ -521,6 +521,7 @@ router.get('/wechat/tgchannel/:id', require('./routes/tencent/wechat/tgchannel')
router.get('/wechat/uread/:userid', require('./routes/tencent/wechat/uread'));
router.get('/wechat/ershicimi/:id', require('./routes/tencent/wechat/ershcimi'));
router.get('/wechat/wjdn/:id', require('./routes/tencent/wechat/wjdn'));
router.get('/wechat/wxnmh/:id', require('./routes/tencent/wechat/wxnmh'));
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'));
+47
View File
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const origin = 'https://www.wxnmh.com/';
const response = await got.get(`${origin}user-${ctx.params.id}.htm`);
const $ = cheerio.load(response.data);
const name = $('#body .col-lg-9 .card-block .col-md-9 h3').text().trim();
const description = $('#body .col-lg-9 .card-block .col-md-9 p').text().trim();
const links = $('#body tr.thread .subject a')
.map((index, ele) => {
const title = $(ele).text();
const link = origin + $(ele).attr('href');
return { title, link };
})
.get();
const item = await Promise.all(
links.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
try {
const res = await got.get(item.link);
const $ = cheerio.load(res.data);
const desc = $('#js_content')
.html()
.replace(/data-src="http/g, 'src="http');
item.description = `<div style="max-width: 800px;margin: 0 auto;text-align: center;">${desc}</div>`;
item.pubDate = date($('.date').text());
return item;
} catch (err) {
return Promise.resolve('');
}
})
)
);
ctx.state.data = {
title: `${name} - 微信公众号`,
link: 'https://www.wxnmh.com/',
description,
item,
};
};