fix(route:aliyun/developer/group): 获取到的全是0 (#9741)

* fix(route:aliyun/developer/group): 获取到的全是0

* Update lib/routes/aliyun/developer/group.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/aliyun/developer/group.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* refactor: migrate to v2

* refactor: use cache.tryGet

* fix: add radar

* fix: article parsing
This commit is contained in:
KotoriK
2022-05-19 00:03:00 +08:00
committed by GitHub
parent f12e407217
commit 6187a08227
7 changed files with 72 additions and 38 deletions
+4 -4
View File
@@ -1922,10 +1922,10 @@ router.get('/socialclub/events/:game?', lazyloadRouteHandler('./routes/socialclu
router.get('/ctfhub/upcoming/:limit?', lazyloadRouteHandler('./routes/ctfhub/upcoming'));
router.get('/ctfhub/search/:limit?/:form?/:class?/:title?', lazyloadRouteHandler('./routes/ctfhub/search'));
// 阿里云
router.get('/aliyun/database_month', lazyloadRouteHandler('./routes/aliyun/database_month'));
router.get('/aliyun/notice/:type?', lazyloadRouteHandler('./routes/aliyun/notice'));
router.get('/aliyun/developer/group/:type', lazyloadRouteHandler('./routes/aliyun/developer/group'));
// 阿里云 migrated to v2
// router.get('/aliyun/database_month', lazyloadRouteHandler('./routes/aliyun/database_month'));
// router.get('/aliyun/notice/:type?', lazyloadRouteHandler('./routes/aliyun/notice'));
// router.get('/aliyun/developer/group/:type', lazyloadRouteHandler('./routes/aliyun/developer/group'));
// 礼物说
router.get('/liwushuo/index', lazyloadRouteHandler('./routes/liwushuo/index.js'));
@@ -10,7 +10,7 @@ module.exports = async (ctx) => {
.map((i, e) => {
const element = $(e);
const title = element.find('a').text().trim();
const link = 'http://mysql.taobao.org' + element.find('a').attr('href').trim();
const link = `http://mysql.taobao.org${element.find('a').attr('href').trim()}/`;
return {
title,
description: '',
@@ -20,20 +20,15 @@ module.exports = async (ctx) => {
.get();
const result = await Promise.all(
list.map(async (item) => {
list.map((item) => {
const link = item.link;
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const itemReponse = await got.get(link);
const itemElement = cheerio.load(itemReponse.data);
item.description = itemElement('.content').html();
ctx.cache.set(link, JSON.stringify(item));
return item;
return ctx.cache.tryGet(link, async () => {
const itemReponse = await got(link);
const itemElement = cheerio.load(itemReponse.data);
item.description = itemElement('.content').html();
return item;
});
})
);
@@ -1,5 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const type = ctx.params.type;
@@ -34,9 +35,13 @@ module.exports = async (ctx) => {
list
.map((index, item) => {
item = $(item);
const desc = item.find('.question-desc');
const description = item.find('.browse').text() + ' ' + desc.find('.answer').text();
return {
title: item.find('p').first().text().trim(),
title: item.find('.question-title').text().trim() || item.find('a p').text().trim(),
link: item.find('a').attr('href'),
pubDate: parseDate(item.find('.time').text()),
description,
};
})
.get(),
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
'/database_month': ['junbaor'],
'/developer/group/:type': ['umm233'],
'/notice/:type?': ['muzea'],
};
@@ -1,9 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const dayjs = require('dayjs');
const customParseFormat = require('dayjs/plugin/customParseFormat');
dayjs.extend(customParseFormat);
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const typeMap = {
0: '9004748',
@@ -28,32 +26,26 @@ module.exports = async (ctx) => {
const title = element.find('a').text().trim();
const link = 'https://help.aliyun.com' + element.find('a').attr('href').trim();
const date = element.find('.y-right').text();
const pubDate = dayjs(`${date} +0800`, 'YYYY-MM-DDHH:mm:ss ZZ');
const pubDate = timezone(parseDate(date), +8);
return {
title,
description: '',
link,
pubDate: pubDate.toString(),
pubDate,
};
})
.get();
const result = await Promise.all(
list.map(async (item) => {
const link = item.link;
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const itemReponse = await got(item.link);
const itemElement = cheerio.load(itemReponse.data);
item.description = itemElement('#se-knowledge').html();
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const itemReponse = await got.get(link);
const itemElement = cheerio.load(itemReponse.data);
item.description = itemElement('#se-knowledge').html();
ctx.cache.set(link, JSON.stringify(item));
return item;
})
return item;
})
)
);
ctx.state.data = {
+32
View File
@@ -0,0 +1,32 @@
module.exports = {
'aliyun.com': {
_name: '阿里云',
developer: [
{
title: '开发者社区 - 主题',
docs: 'https://docs.rsshub.app/programming.html#a-li-yun',
source: ['/group/:type'],
target: '/aliyun/developer/group/:type',
},
],
help: [
{
title: '公告',
docs: 'https://docs.rsshub.app/programming.html#a-li-yun',
source: ['/noticelist/:type', '/'],
target: (params) => `/aliyun/notice${params.type ? '/' + params.type.replace('.html', '') : ''}`,
},
],
},
'taobao.org': {
_name: '阿里云',
mysql: [
{
title: '数据库内核月报',
docs: 'https://docs.rsshub.app/programming.html#a-li-yun',
source: ['/monthly', '/'],
target: '/aliyun/database_month',
},
],
},
};
+5
View File
@@ -0,0 +1,5 @@
module.exports = (router) => {
router.get('/database_month', require('./database_month'));
router.get('/developer/group/:type', require('./developer/group'));
router.get('/notice/:type?', require('./notice'));
};