From 567df083995f5de074afb82d5f74102b145a8f9a Mon Sep 17 00:00:00 2001 From: Bin Wang Date: Sun, 18 Sep 2022 06:08:01 -0400 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E7=BB=99=20v2ex=20topics=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20comments=20=E5=AD=97=E6=AE=B5=20(#10819)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 给 v2ex topics 添加 comments 字段 * refactor: use parse-date --- lib/routes/v2ex/topics.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/routes/v2ex/topics.js b/lib/routes/v2ex/topics.js index 71ad120a98..db3097d9c1 100644 --- a/lib/routes/v2ex/topics.js +++ b/lib/routes/v2ex/topics.js @@ -1,14 +1,10 @@ const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const type = ctx.params.type; - const response = await got({ - method: 'get', - url: `https://www.v2ex.com/api/topics/${type}.json`, - }); - - const data = response.data; + const { data } = await got(`https://www.v2ex.com/api/topics/${type}.json`); let title; if (type === 'hot') { @@ -25,10 +21,10 @@ module.exports = async (ctx) => { title: item.title, description: `${item.member.username}: ${item.content_rendered}`, content: { text: item.content, html: item.content_rendered }, - pubDate: new Date(item.created * 1000).toUTCString(), - guid: item.id, + pubDate: parseDate(item.created, 'X'), link: item.url, author: item.member.username, + comments: item.replies, })), }; };