From 7792838f2be236976c932792636d6300c4cd50eb Mon Sep 17 00:00:00 2001
From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com>
Date: Thu, 10 Oct 2019 11:43:34 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=E3=80=90?=
=?UTF-8?q?=E5=B0=91=E6=95=B0=E6=B4=BE=20sspai=20=E6=8C=89=E6=A0=87?=
=?UTF-8?q?=E7=AD=BE=E6=9B=B4=E6=96=B0=E6=96=87=E7=AB=A0=E3=80=91=E7=9A=84?=
=?UTF-8?q?=E6=94=AF=E6=8C=81=20(#3220)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/new-media.md | 4 ++++
lib/router.js | 1 +
lib/routes/sspai/tag.js | 45 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+)
create mode 100644 lib/routes/sspai/tag.js
diff --git a/docs/new-media.md b/docs/new-media.md
index e43896dce2..166b8e6060 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -603,6 +603,10 @@ pageClass: routes
+### 标签订阅
+
+
+
## 世界卫生组织
### 媒体中心
diff --git a/lib/router.js b/lib/router.js
index 18812f588e..f2d18264b7 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -716,6 +716,7 @@ router.get('/sspai/column/:id', require('./routes/sspai/column'));
router.get('/sspai/author/:id', require('./routes/sspai/author'));
router.get('/sspai/topics', require('./routes/sspai/topics'));
router.get('/sspai/topic/:id', require('./routes/sspai/topic'));
+router.get('/sspai/tag/:keyword', require('./routes/sspai/tag'));
// 异次元软件世界
router.get('/iplay/home', require('./routes/iplay/home'));
diff --git a/lib/routes/sspai/tag.js b/lib/routes/sspai/tag.js
new file mode 100644
index 0000000000..bdc45a9117
--- /dev/null
+++ b/lib/routes/sspai/tag.js
@@ -0,0 +1,45 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+
+module.exports = async (ctx) => {
+ const keyword = ctx.params.keyword;
+ const api_url = `https://sspai.com/api/v1/articles?offset=0&limit=50&has_tag=1&tag=${keyword}&include_total=false`;
+ const host = `https://beta.sspai.com/tag/${keyword}`;
+ const resp = await got({
+ method: 'get',
+ url: api_url,
+ headers: {
+ Referer: host,
+ },
+ });
+ const data = resp.data.list;
+ const items = await Promise.all(
+ data.map(async (item) => {
+ const link = `https://sspai.com/post/${item.id}`;
+ let description = ``;
+ const key = item.id;
+ const value = await ctx.cache.get(key);
+ if (value) {
+ description = value;
+ } else {
+ const response = await got({ method: 'get', url: link, headers: { Referer: host } });
+ const $ = cheerio.load(response.data);
+ description = $('div.content.wangEditor-txt.clock').html();
+ ctx.cache.set(key, description);
+ }
+ return {
+ title: item.title.trim(),
+ description: description,
+ link: link,
+ pubDate: new Date(item.released_at * 1000).toUTCString(),
+ author: item.author.nickname,
+ };
+ })
+ );
+ ctx.state.data = {
+ title: `#${keyword} - 少数派`,
+ link: host,
+ description: `${keyword} 更新推送 `,
+ item: items,
+ };
+};