diff --git a/docs/programming.md b/docs/programming.md index 3c402c816d..7596bdd34a 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -824,6 +824,35 @@ GitHub 官方也提供了一些 RSS: +## 登链社区 + +### 文章 + + + +| id | 分类 | +|----------|--------------| +| all | 全部 | +| DApp | 去中心化应用 | +| chains | 公链 | +| 联盟链 | 联盟链 | +| scaling | Layer2 | +| langs | 编程语言 | +| security | 安全 | +| dst | 存储 | +| basic | 理论研究 | +| other | 其他 | + + +| id | 排序方式 | +|----------|------------| +| newest | 最新 | +| featured | 精选(默认) | +| featured | 最赞 | +| hottest | 最热 | + + + ## 极客时间 ### 专栏文章 diff --git a/lib/v2/learnblockchain/maintainer.js b/lib/v2/learnblockchain/maintainer.js new file mode 100644 index 0000000000..f44f2dc23a --- /dev/null +++ b/lib/v2/learnblockchain/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/posts/:cid/:sort?': ['running-grass'], +}; diff --git a/lib/v2/learnblockchain/posts.js b/lib/v2/learnblockchain/posts.js new file mode 100644 index 0000000000..341b94187f --- /dev/null +++ b/lib/v2/learnblockchain/posts.js @@ -0,0 +1,42 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); +const { + parseRelativeDate +} = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const cid = ctx.params.cid || 'all'; + const sort = ctx.params.sort; + + let url = 'https://learnblockchain.cn/categories/'; + url += cid + '/'; + + if (sort) { + url += sort + '/'; + } + + const response = await got(url); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('div.stream-list section.stream-list-item'); + + ctx.state.data = { + title: `登链社区--${cid}`, + link: url, + description: `登链社区`, + item: list && list.map((idx, ite) => { + const item = $(ite); + const json = { + title: item.find('h2.title').text().trim(), + description: item.find('div.excerpt').text().trim(), + pubDate: parseRelativeDate(item.find('.author li:nth-child(2)').text().replace('发布于', '').trim()), + link: item.find('h2.title a').attr('href').trim(), + author: item.find('.author li:nth-child(1)').text().trim(), + }; + + return json; + }).get(), + }; + +}; diff --git a/lib/v2/learnblockchain/radar.js b/lib/v2/learnblockchain/radar.js new file mode 100644 index 0000000000..1e746ca12f --- /dev/null +++ b/lib/v2/learnblockchain/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'learnblockchain.cn': { + _name: '登链社区', + '.': [{ + title: '分类文章', + docs: 'https://docs.rsshub.app/programming.html#deng-lian-she-qu-wen-zhang', + source: '/categories/:cid/:sort?', + target: (params) => `/learnblockchain/posts/${params.cid}/${params.sort}`, + }, + { + title: '全部文章', + docs: 'https://docs.rsshub.app/programming.html#deng-lian-she-qu-wen-zhang', + source: '*', + target: () => '/learnblockchain/posts/all/', + } + + ], + }, +}; diff --git a/lib/v2/learnblockchain/router.js b/lib/v2/learnblockchain/router.js new file mode 100644 index 0000000000..85a83e667a --- /dev/null +++ b/lib/v2/learnblockchain/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/posts/:cid/:sort?', require('./posts')); +};