feat: Add pubTime for New York Times (#3021)

This commit is contained in:
QuantumGhost 2019-09-09 03:01:42 +00:00 committed by DIYgod
parent df1680903d
commit 130976f747
3 changed files with 10 additions and 4 deletions

View File

@ -240,7 +240,7 @@ category 对应的关键词有
### 官方 RSS
<Route author="HenryQW" example="/nytimes/dual" path="/nytimes/index/:lang?" :paramsDesc="['语言, 缺省中文']">
<Route author="HenryQW" example="/nytimes/dual" path="/nytimes/:lang?" :paramsDesc="['语言, 缺省中文']">
通过提取文章全文,以提供比官方源更佳的阅读体验。

View File

@ -25,13 +25,14 @@ module.exports = async (ctx) => {
const items = await Promise.all(
post.map(async (item) => {
const link = item.link;
const description = await ctx.cache.tryGet(`nyt: ${link}`, async () => {
const result = await ctx.cache.tryGet(`nyt: ${link}`, async () => {
const response = await got.get(link);
return utils.ProcessFeed(response.data).description;
return utils.ProcessFeed(response.data);
});
item.description = description;
item.pubDate = result.pubDate;
item.description = result.description;
return Promise.resolve(item);
})
);

View File

@ -71,6 +71,11 @@ const ProcessFeed = (data, hasEnVersion = false) => {
}
}
const time = $('time').attr('datetime');
if (time) {
result.pubDate = new Date(time).toUTCString();
}
result.description = content.html();
return result;