Skip to content

Commit

Permalink
增加: 小程序插件 (DIYgod#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyqfer authored and DIYgod committed Nov 7, 2018
1 parent 97c196e commit 3836d4b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ RSSHub 提供下列 API 接口:

<route name="公众平台系统公告栏目" author="xyqfer" example="/wechat/announce" path="/wechat/announce" />

<route name="小程序插件" author="xyqfer" example="/wechat/miniprogram/plugins" path="/wechat/miniprogram/plugins" />

### 简书

<route name="首页" author="DIYgod HenryQW" example="/jianshu/home" path="/jianshu/home"/>
Expand Down
1 change: 1 addition & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,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/announce', require('./routes/tencent/wechat/announce'));
router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins'));

// All the Flight Deals
router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));
Expand Down
59 changes: 59 additions & 0 deletions routes/tencent/wechat/miniprogram/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const axios = require('../../../../utils/axios');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const link = 'https://developers.weixin.qq.com/community/plugins';
const response = await axios({
method: 'post',
url: `https://developers.weixin.qq.com/community/ngi/plugins/cases?random=${Math.random()}`,
headers: {
Referer: link,
},
});

const { pluginCases } = response.data.data;
const resultItem = await Promise.all(
pluginCases.map(async (plugin) => {
const item = {
title: plugin.title,
description: '',
link: `https://developers.weixin.qq.com/community/develop/doc/${plugin.docid}`,
author: plugin.nickname,
pubDate: new Date(plugin.createTime * 1000).toUTCString(),
};
const url = `https://developers.weixin.qq.com/community/ngi/doc/detail/${plugin.docid}`;
const key = `miniprogram-plugin: ${url}`;
const value = await ctx.cache.get(key);

if (value) {
item.description = value;
} else {
const pluginDetail = await axios({
method: 'get',
url: `${url}?random=${Math.random()}`,
headers: {
Referer: link,
},
});
const id = 'x-rsshub';
const $ = cheerio.load(`<div id="${id}">${pluginDetail.data.data.Content}</div>`);
$('img').each((index, item) => {
item = $(item);
item.attr('src', item.attr('data-src'));
item.attr('referrerpolicy', 'no-referrer');
});

item.description = $(`#${id}`).html();
ctx.cache.set(key, item.description, 24 * 60 * 60);
}

return Promise.resolve(item);
})
);

ctx.state.data = {
title: '微信小程序插件',
link,
item: resultItem,
};
};

0 comments on commit 3836d4b

Please sign in to comment.