From 000c7e0f57890fe2272f646d6fde7325796791c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E5=B0=8F=E8=8D=89?=
<467195537@qq.com>
Date: Thu, 2 Feb 2023 20:54:40 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20=E5=A2=9E=E5=8A=A0=E7=99=BB?=
=?UTF-8?q?=E9=93=BE=E7=A4=BE=E5=8C=BA=20(#11759)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): 增加登链社区
* fix(route): 修复路由找不到的问题
* fix(route): 修复eslint问题
* fix(route): 修复deepscan报错
* Update docs/programming.md
* Update lib/v2/learnblockchain/posts.js
* fix(route): 修复错误日期
---------
---
docs/programming.md | 29 +++++++++++++++++++
lib/v2/learnblockchain/maintainer.js | 3 ++
lib/v2/learnblockchain/posts.js | 42 ++++++++++++++++++++++++++++
lib/v2/learnblockchain/radar.js | 19 +++++++++++++
lib/v2/learnblockchain/router.js | 3 ++
5 files changed, 96 insertions(+)
create mode 100644 lib/v2/learnblockchain/maintainer.js
create mode 100644 lib/v2/learnblockchain/posts.js
create mode 100644 lib/v2/learnblockchain/radar.js
create mode 100644 lib/v2/learnblockchain/router.js
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'));
+};