diff --git a/docs/programming.md b/docs/programming.md index f7c2244b1..c7694cd4f 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -4,6 +4,12 @@ pageClass: routes # 编程 +## AI 研习社 + +### 最新 + + + ## AlgoCasts ### 视频更新 diff --git a/lib/router.js b/lib/router.js index e5c820975..88f6788e0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1418,4 +1418,7 @@ router.get('/outagereport/:name/:count?', require('./routes/outagereport/service // sixthtone router.get('/sixthtone/news', require('./routes/sixthtone/news')); +// AI研习社 +router.get('/aiyanxishe/', require('./routes/aiyanxishe/home')); + module.exports = router; diff --git a/lib/routes/aiyanxishe/home.js b/lib/routes/aiyanxishe/home.js new file mode 100644 index 000000000..91a261c2f --- /dev/null +++ b/lib/routes/aiyanxishe/home.js @@ -0,0 +1,101 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'GET', + url: 'https://www.leiphone.com/club/api?page=1&size=30&is_hot=0&is_recommend=0&tag=&parent_tag=', + headers: { + Referer: `https://www.leiphone.com/club/api?page=1&size=30&is_hot=0&is_recommend=0&tag=&parent_tag='`, + }, + }); + + const ProcessFeed = (type, data) => { + let description = ''; + let author = ''; + switch (type) { + case 'blog': // 博客 + description = data.content; + author = data.user.nickname; + break; + case 'question': // 问答 + description = data.content; + author = data.user.nickname; + break; + case 'article': // 翻译 + description = ``; + data.paragraphs.forEach((element) => { + description += ``; + }); + description += + '
${data.title} ${data.zh_title}
${element.content} ${element.zh_content.content}
\ + '; + author = data.user.nickname; + break; + case 'paper': // 论文 + description = `

标题

${data.paper.title}

`; + description += `

作者

${data.paper.author.toString()}

`; + description += `

下载地址

${data.paper.url}

`; + description += `

发布时间

${data.paper.publish_time}

`; + description += `

摘要

${data.paper.description}

`; + description += `

推荐理由

${data.paper.userInfo.nickname} : ${data.paper.recommend_reason}

`; + author = data.paper.userInfo.nickname; + break; + default: + description = '暂不支持此类型,请到 https://github.com/DIYgod/RSSHub/issues 反馈'; + break; + } + + // 提取内容 + return { author, description }; + }; + + const items = await Promise.all( + response.data.data.all.map(async (item) => { + let itemUrl = item.url; + + // 修复论文链接 + if (item.type === 'paper') { + itemUrl = 'https://www.leiphone.com/club/api/spaper/detail?id=' + item.id; + } + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await got({ + method: 'get', + url: itemUrl, + }); + + const result = ProcessFeed(item.type, response.data.data); + + const single = { + title: item.zh_title, + description: result.description, + pubDate: new Date(parseFloat(item.published_time + '000')).toUTCString(), + link: itemUrl, + author: result.author, + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `AI研习社`, + link: `https://ai.yanxishe.com/`, + description: '专注AI技术发展与AI工程师成长的求知平台', + item: items, + }; +};