From 3973071c11f9791f3b34f696c1fefa6d2d78aef1 Mon Sep 17 00:00:00 2001
From: Hendricks Zheng <54502919+HendricksZheng@users.noreply.github.com>
Date: Sun, 15 Sep 2019 23:48:32 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=BD=91=E6=98=93=E5=8F=B7=20(#3?=
=?UTF-8?q?087)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Update router.js
* Update new-media.md
* Create dy.js
---
docs/new-media.md | 14 +++++++++++-
lib/router.js | 3 +++
lib/routes/netease/dy.js | 49 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 1 deletion(-)
create mode 100644 lib/routes/netease/dy.js
diff --git a/docs/new-media.md b/docs/new-media.md
index 8727330e0..5d48e46d2 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -614,7 +614,19 @@ pageClass: routes
1. 通过浏览器搜索相关搜狐号 `果壳 site: mp.sohu.com`。
-1. 通过浏览器控制台执行 `cfgs.author_id`,返回的即为搜狐号 ID。
+2. 通过浏览器控制台执行 `cfgs.author_id`,返回的即为搜狐号 ID。
+
+
+
+## 网易号
+
+### 更新
+
+
+
+1. 在[网易号搜索页面](https://dy.163.com/v2/media/tosearch.html) 搜索想要订阅的网易号。
+2. 打开网易号文章页面。
+3. 通过浏览器控制台执行 `$('#contain').dataset.wemediaid`,返回的即为网易号 ID。
diff --git a/lib/router.js b/lib/router.js
index f9fdd78fb..b8833cdc3 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1729,4 +1729,7 @@ router.get('/leemeng', require('./routes/blogs/leemeng'));
// 中国地质大学
router.get('/cug/graduate', require('./routes/cug/graduate'));
+// 网易 - 网易号
+router.get('/netease/dy/:id', require('./routes/netease/dy'));
+
module.exports = router;
diff --git a/lib/routes/netease/dy.js b/lib/routes/netease/dy.js
new file mode 100644
index 000000000..f1840c962
--- /dev/null
+++ b/lib/routes/netease/dy.js
@@ -0,0 +1,49 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const date = require('@/utils/date');
+const iconv = require('iconv-lite');
+
+module.exports = async (ctx) => {
+ const { id } = ctx.params;
+
+ const response = await got.get(`http://dy.163.com/v2/article/list.do?pageNo=1&wemediaId=${id}&size=10`);
+
+ const list = response.data.data.list;
+ let author, link;
+
+ const items = await Promise.all(
+ list.map(async (e) => {
+ if (e.docid) {
+ e.link = 'http://dy.163.com/v2/article/detail/' + e.docid + '.html';
+ }
+ const response = await ctx.cache.tryGet(
+ e.link,
+ async () =>
+ (await got.get(e.link, {
+ responseType: 'buffer',
+ })).data
+ );
+ const html = iconv.decode(response, 'gbk');
+ const $ = cheerio.load(html, { decodeEntities: false });
+
+ const article = $('div.article_box > div.content');
+
+ const single = {
+ title: e.title,
+ link: e.link,
+ description: article.html(),
+ pubDate: date(e.ptime, 8),
+ author: e.source,
+ };
+
+ return Promise.resolve(single);
+ })
+ );
+
+ ctx.state.data = {
+ title: `网易号 - ${author}`,
+ link,
+ description: '',
+ item: items,
+ };
+};