diff --git a/docs/README.md b/docs/README.md index e3a9db33d9..bce2b6e17f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -391,6 +391,8 @@ RSSHub 提供下列 API 接口: + + diff --git a/lib/router.js b/lib/router.js index db0a0fe84e..581b1ea9a3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -497,6 +497,7 @@ router.get('/bugly/changelog/:platform', require('./routes/tencent/bugly/changel // wechat router.get('/wechat/wasi/:id', require('./routes/tencent/wechat/wasi')); +router.get('/wechat/wemp/:id', require('./routes/tencent/wechat/wemp')); router.get('/wechat/announce', require('./routes/tencent/wechat/announce')); router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins')); diff --git a/lib/routes/tencent/wechat/wemp.js b/lib/routes/tencent/wechat/wemp.js new file mode 100644 index 0000000000..07f850bb78 --- /dev/null +++ b/lib/routes/tencent/wechat/wemp.js @@ -0,0 +1,50 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +// const timezone = require('../../utils/timezone'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + + const response = await axios.get(`https://wemp.app/accounts/${id}`); + + const $ = cheerio.load(response.data); + const author = $('.mp-info__title') + .text() + .trim(); + + const year = new Date().getFullYear(); + const items = $('.post-item__main') + .slice(0, 10) + .get() + .map((e) => ({ + title: $(e) + .find('.post-item__title') + .text() + .trim(), + link: `https://wemp.app${$(e) + .find('.post-item__title') + .attr('href')}`, + pubDate: timezone( + `${year} ${$(e) + .find('.post-item__date') + .text() + .trim()}`, + 8 + ), + author, + })); + + // to be replaced + function timezone(html, timezone) { + return new Date(new Date(html).getTime() - 60 * 60 * 1000 * (timezone + new Date().getTimezoneOffset() / 60)).toUTCString(); + } + + ctx.state.data = { + title: `微信公众号 - ${author}`, + link: `https://wemp.app/accounts/${id}/`, + description: $('.mp-info__value') + .text() + .trim(), + item: items, + }; +};