From fbe26fe883395ffa13231511eefcf2ffc1bf11d1 Mon Sep 17 00:00:00 2001
From: zoenglinghou <11689106+zoenglinghou@users.noreply.github.com>
Date: Thu, 16 Jan 2020 14:12:52 +0100
Subject: [PATCH] feat: Add China Dialogue (#3748)
---
docs/en/traditional-media.md | 22 ++++++++++++
docs/traditional-media.md | 24 ++++++++++++-
lib/router.js | 4 +++
lib/routes/chinadialogue/column.js | 58 ++++++++++++++++++++++++++++++
lib/routes/chinadialogue/topics.js | 55 ++++++++++++++++++++++++++++
5 files changed, 162 insertions(+), 1 deletion(-)
create mode 100644 lib/routes/chinadialogue/column.js
create mode 100644 lib/routes/chinadialogue/topics.js
diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md
index e699841e2b..d6a5db49e3 100644
--- a/docs/en/traditional-media.md
+++ b/docs/en/traditional-media.md
@@ -26,6 +26,28 @@ Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/1062
+## China Dialogue
+
+### Topics
+
+
+
+| Business | Cities | Climate Change | Conservation | Governance & Law | Health and Food | Natural Disasters | Pollution | Science & Tech | Security | Water |
+| -------- | ------ | ------------------------- | ------------ | ------------------ | --------------- | ----------------- | --------- | ---------------- | -------- | ----- |
+| business | cities | climate-change-and-energy | conservation | governance-and-law | health-and-food | natural-disasters | pollution | science-and-tech | security | water |
+
+
+
+### Columns
+
+
+
+| Articles | Blogs | Culture | Reports |
+| -------- | ----- | ------- | ------- |
+| article | blog | culture | reports |
+
+
+
## China Times
### News
diff --git a/docs/traditional-media.md b/docs/traditional-media.md
index b086f68187..407618e904 100644
--- a/docs/traditional-media.md
+++ b/docs/traditional-media.md
@@ -390,7 +390,7 @@ category 对应的关键词有
分类:
| zx | twhk | dwzw | zrdl | lskg | smyx | shbk | kjqy |
-| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
+| ---- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| 最新 | 天文航空 | 动物植物 | 自然地理 | 历史考古 | 生命医学 | 生活百科 | 科技前沿 |
@@ -504,3 +504,25 @@ category 对应的关键词有
| 即時 | 政治 | 言論 | 生活 | 娛樂 | 財經 | 社會 | 話題 | 快點 TV | 國際 | 軍事 | 兩岸 | 時尚 | 體育 | 科技 | 玩食 | 專輯 |
+
+## 中外对话
+
+### 主题
+
+
+
+| 商业 | 城市化 | 气候变化与能源 | 自然保护 | 管制与法律 | 健康与食品 | 自然灾害 | 污染 | 科学与技术 | 安全 | 水 |
+| -------- | ------ | ------------------------- | ------------ | ------------------ | --------------- | ----------------- | --------- | ---------------- | -------- | ----- |
+| business | cities | climate-change-and-energy | conservation | governance-and-law | health-and-food | natural-disasters | pollution | science-and-tech | security | water |
+
+
+
+### 栏目
+
+
+
+| 文章 | 博客 | 文化 | 报告 |
+| ------- | ---- | ------- | ------- |
+| article | blog | culture | reports |
+
+
diff --git a/lib/router.js b/lib/router.js
index 3aa19eea94..647f76b2f8 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2142,4 +2142,8 @@ router.get('/apnews/topics/:topic', require('./routes/apnews/topics'));
// discuz
router.get('/discuz/:link', require('./routes/discuz/discuz'));
+// China Dialogue 中外对话
+router.get('/chinadialogue/topics/:topic', require('./routes/chinadialogue/topics'));
+router.get('/chinadialogue/:column', require('./routes/chinadialogue/column'));
+
module.exports = router;
diff --git a/lib/routes/chinadialogue/column.js b/lib/routes/chinadialogue/column.js
new file mode 100644
index 0000000000..30c0064086
--- /dev/null
+++ b/lib/routes/chinadialogue/column.js
@@ -0,0 +1,58 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+module.exports = async (ctx) => {
+ const column = ctx.params.column;
+
+ const response = await got({
+ method: 'get',
+ url: `https://www.chinadialogue.net/${column}`,
+ });
+
+ const data = response.data;
+
+ const $ = cheerio.load(data);
+ const list = $('article.main-listing');
+ let itemPicUrl;
+ let title;
+ let description;
+
+ ctx.state.data = {
+ title: $('title').text(),
+ link: `https://www.chinadialogue.net/${column}`,
+ item:
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ itemPicUrl = item.find('img.img-responsive').attr('src');
+
+ title = [];
+ description = [];
+
+ item.find('h1').each(function(index, element) {
+ title.push(
+ $(element)
+ .text()
+ .replace(/(\r\n|\n|\r)/gm, '')
+ );
+ });
+
+ item.find('p').each(function(index, element) {
+ description.push(
+ $(element)
+ .text()
+ .replace(/(\r\n|\n|\r)/gm, '')
+ );
+ });
+
+ return {
+ title: title.join(' | '),
+ description: `
${description.join('
')}
`,
+ pubDate: item.find('time.blog').attr('datetime'),
+ link: item.find('a').attr('href'),
+ };
+ })
+ .get(),
+ };
+};
diff --git a/lib/routes/chinadialogue/topics.js b/lib/routes/chinadialogue/topics.js
new file mode 100644
index 0000000000..e2a2ce8a9b
--- /dev/null
+++ b/lib/routes/chinadialogue/topics.js
@@ -0,0 +1,55 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+module.exports = async (ctx) => {
+ const topic = ctx.params.topic;
+
+ const response = await got({
+ method: 'get',
+ url: `https://www.chinadialogue.net/topics/${topic}`,
+ });
+
+ const data = response.data;
+
+ const $ = cheerio.load(data);
+ const list = $('article.excerpt.col-md-6');
+ let itemPicUrl;
+ let title;
+ let description;
+
+ ctx.state.data = {
+ title: $('title')
+ .text()
+ .replace(/( 主题 >| Topics >)/gm, ''),
+ link: `https://www.chinadialogue.net/topics/${topic}`,
+ item:
+ list &&
+ list
+ .map((index, item) => {
+ item = $(item);
+ itemPicUrl = item.find('img.img-responsive').attr('src');
+
+ title = [];
+ description = [];
+
+ item.find('h1').each(function(index, element) {
+ title.push(
+ $(element)
+ .text()
+ .replace(/(\r\n|\n|\r)/gm, '')
+ );
+ });
+
+ item.find('p').each(function(index, element) {
+ description.push($(element).text());
+ });
+
+ return {
+ title: title.join(' | '),
+ description: `${description.join('
')}
`,
+ link: item.find('a').attr('href'),
+ };
+ })
+ .get(),
+ };
+};