feat: 微信开放平台相关路由代码简化 (#3804)

This commit is contained in:
Henry Wang
2020-01-31 09:37:58 +00:00
committed by GitHub
parent a86d033ad1
commit f87d381609
8 changed files with 35 additions and 117 deletions

View File

@@ -0,0 +1,33 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'https://developers.weixin.qq.com/miniprogram/dev/framework/release/';
const response = await got({
method: 'get',
url: link,
});
const data = response.data;
const $ = cheerio.load(data);
const name = $('#docContent .content h1')
.text()
.replace(/[\s|#]/g, '');
const titles = $('#docContent .content h3').map((i, ele) =>
$(ele)
.text()
.replace(/[\s|#]/g, '')
);
const list = $('#docContent > .content ol')
.map((i, ele) => ({
title: titles[i],
description: $(ele).html(),
}))
.get();
ctx.state.data = {
title: `${name}最新动态`,
link: link,
item: list,
description: '基础库更新日志RSS',
};
};