From c21b66ffc8cb54098b2dbcec39cef42640a32d63 Mon Sep 17 00:00:00 2001
From: FlashWingShadow <45242683+FlashWingShadow@users.noreply.github.com>
Date: Mon, 29 Jun 2020 01:01:44 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=94=B5=E5=95=86=E6=8A=A5=20(#5?=
=?UTF-8?q?078)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/new-media.md | 12 ++++++++++++
lib/router.js | 3 +++
lib/routes/dsb/area.js | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+)
create mode 100644 lib/routes/dsb/area.js
diff --git a/docs/new-media.md b/docs/new-media.md
index 5623e00d9..c50b05e76 100755
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -429,6 +429,18 @@ Supported sub-sites:
+## 电商报
+
+### 分区
+
+
+
+area 分区选项
+
+| 零售 | 物流 | O2O | 金融 | B2B | 人物 | 跨境 | 行业观察 |
+| -------- | ----- | --- | ------- | --- | ----- | ------- | -------- |
+| lingshou | wuliu | O2O | jinrong | B2B | renwu | kuajing | guancha |
+
## 电商在线
### 电商在线
diff --git a/lib/router.js b/lib/router.js
index c5e562fa1..c7c392a81 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2896,4 +2896,7 @@ router.get('/go-weekly', require('./routes/go-weekly'));
// AMD
router.get('/amd/graphicsdrivers/:id/:rid?', require('./routes/amd/graphicsdrivers'));
+// 电商报
+router.get('/dsb/area/:area', require('./routes/dsb/area'));
+
module.exports = router;
diff --git a/lib/routes/dsb/area.js b/lib/routes/dsb/area.js
new file mode 100644
index 000000000..3197707ae
--- /dev/null
+++ b/lib/routes/dsb/area.js
@@ -0,0 +1,34 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+module.exports = async (ctx) => {
+ const area = ctx.params.area;
+ const host = 'www.dsb.cn';
+ const areaUrl = `http://${host}/${area}`;
+ const areaResp = await got(areaUrl);
+ const $ = cheerio.load(areaResp.data);
+ const areaName = $('.new-list-title').text();
+ const newsUrls = $('ul.new-list-cons > li > a')
+ .map((i, e) => $(e).attr('href'))
+ .get();
+
+ ctx.state.data = {
+ title: `电商报 - ${areaName}`,
+ link: areaUrl,
+ item: await Promise.all(
+ newsUrls.map(
+ async (url) =>
+ await ctx.cache.tryGet(url, async () => {
+ const newsResp = await got(url);
+ const $ = cheerio.load(newsResp.data);
+ return {
+ title: $('.new-content > h2').text(),
+ link: url,
+ pubDate: $('.new-content-info > span:nth-child(3)').text(),
+ description: $('div.new-content-con').html(),
+ };
+ })
+ )
+ ),
+ };
+};