From 45b6be29bce4053821cd8552fc7fa4c5144dfcc8 Mon Sep 17 00:00:00 2001
From: Who's Sure <73735729+WhoIsSure@users.noreply.github.com>
Date: Mon, 2 Nov 2020 19:11:55 +0800
Subject: [PATCH] feat: add grand-challenge (#6082)
---
docs/other.md | 10 ++++++++
lib/router.js | 6 +++++
lib/routes/grandchallenge/challenges.js | 33 ++++++++++++++++++++++++
lib/routes/grandchallenge/user.js | 34 +++++++++++++++++++++++++
4 files changed, 83 insertions(+)
create mode 100644 lib/routes/grandchallenge/challenges.js
create mode 100644 lib/routes/grandchallenge/user.js
diff --git a/docs/other.md b/docs/other.md
index 5fe807a661..bfe697b426 100644
--- a/docs/other.md
+++ b/docs/other.md
@@ -97,6 +97,16 @@ pageClass: routes
+## Grand-Challenge
+
+### Challenge 列表
+
+
+
+### 用户参加的 Challenge
+
+
+
## HackerOne
### HackerOne Hacker Activity
diff --git a/lib/router.js b/lib/router.js
index b1360cdac4..1cfdc3f6c9 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -3453,4 +3453,10 @@ router.get('/wsj/:lang/:category', require('./routes/wsj/index'));
// China File
router.get('/chinafile/:category?', require('./routes/chinafile/index'));
+// Grand-Challenge-user
+router.get('/grandchallenge/user/:id', require('./routes/grandchallenge/user'));
+
+// Grand-Challenge-Challenges
+router.get('/grandchallenge/challenges', require('./routes/grandchallenge/challenges'));
+
module.exports = router;
diff --git a/lib/routes/grandchallenge/challenges.js b/lib/routes/grandchallenge/challenges.js
new file mode 100644
index 0000000000..86fca0e3b8
--- /dev/null
+++ b/lib/routes/grandchallenge/challenges.js
@@ -0,0 +1,33 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+module.exports = async (ctx) => {
+ const response = await got({
+ method: 'get',
+ url: 'https://grand-challenge.org/challenges',
+ });
+
+ const data = response.data;
+
+ const $ = cheerio.load(data);
+ const list = $('.card');
+
+ ctx.state.data = {
+ title: 'Grand-Challenge-challenges',
+ link: 'https://grand-challenge.org/challenges',
+ item:
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ const itemPicUrl = item.find('img').attr('src');
+ const description = item.find('a[data-description]').attr('data-description') || 'No description';
+ return {
+ title: item.find('h5').text(),
+ description: `${description}
`,
+ link: item.find('.stretched-link').attr('href'),
+ };
+ })
+ .get(),
+ };
+};
diff --git a/lib/routes/grandchallenge/user.js b/lib/routes/grandchallenge/user.js
new file mode 100644
index 0000000000..767ea9f92b
--- /dev/null
+++ b/lib/routes/grandchallenge/user.js
@@ -0,0 +1,34 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+module.exports = async (ctx) => {
+ const id = ctx.params.id;
+ const response = await got({
+ method: 'get',
+ url: `https://grand-challenge.org/users/${id}`,
+ });
+
+ const data = response.data;
+
+ const $ = cheerio.load(data);
+ const list = $('.card');
+
+ ctx.state.data = {
+ title: `${id}'s participations`,
+ link: `https://grand-challenge.org/users/${id}`,
+ item:
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ const itemPicUrl = item.find('img').attr('src');
+ const description = item.find('.card-text').text() || 'No description';
+ return {
+ title: item.find('h5').text(),
+ description: `${description}
`,
+ link: item.find('.stretched-link').attr('href'),
+ };
+ })
+ .get(),
+ };
+};