From 237625808d1bfb4f276b3333b0dc8cebf5559bc6 Mon Sep 17 00:00:00 2001 From: Laam Pui Date: Tue, 3 Nov 2020 19:28:36 +0800 Subject: [PATCH] feat: add wxnmh.com #5324 (#6063) --- docs/new-media.md | 4 +++ lib/router.js | 1 + lib/routes/tencent/wechat/wxnmh.js | 47 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 lib/routes/tencent/wechat/wxnmh.js diff --git a/docs/new-media.md b/docs/new-media.md index 42925d43aa..fa493af694 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1453,6 +1453,10 @@ column 为 third 时可选的 category: +### 公众号 (wxnmh.com 来源) + + + ### 公众号栏目 (非推送 & 历史消息) diff --git a/lib/router.js b/lib/router.js index e9fbb69ea9..1b029baef7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/tencent/wechat/wxnmh.js b/lib/routes/tencent/wechat/wxnmh.js new file mode 100644 index 0000000000..c14c451035 --- /dev/null +++ b/lib/routes/tencent/wechat/wxnmh.js @@ -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 = `
${desc}
`; + item.pubDate = date($('.date').text()); + return item; + } catch (err) { + return Promise.resolve(''); + } + }) + ) + ); + + ctx.state.data = { + title: `${name} - 微信公众号`, + link: 'https://www.wxnmh.com/', + description, + item, + }; +};