feat(route): 给 v2ex topics 添加 comments 字段 (#10819)

* feat(route): 给 v2ex topics 添加 comments 字段

* refactor: use parse-date
This commit is contained in:
Bin Wang 2022-09-18 06:08:01 -04:00 committed by GitHub
parent 1400df76cc
commit 567df08399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 8 deletions

View File

@ -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,
})),
};
};