feat: improve initium fetching performance & fix time zone (#6496)

This commit is contained in:
oppilate
2020-12-23 17:51:07 +00:00
committed by GitHub
parent cfef5182ed
commit 162dadb12c
+19 -11
View File
@@ -95,6 +95,11 @@ module.exports = async (ctx) => {
// 如果model=author,那就是avatar;否则都是cover,要么就没封面
const image = response.data[model] && (response.data[model].cover || response.data[model].avatar);
function fixDate(date) {
// The date is mistakenly declared as UTC, but actually it's UTC+08:00
return date.replace(/Z$/, '+08:00');
}
const getFullText = async (slug) => {
let content = await ctx.cache.get(slug + language);
if (content) {
@@ -160,17 +165,20 @@ module.exports = async (ctx) => {
articles
.filter((a) => a.article)
.slice(0, token === 'Basic YW5vbnltb3VzOkdpQ2VMRWp4bnFCY1ZwbnA2Y0xzVXZKaWV2dlJRY0FYTHY=' && key.iapReceipt === undefined ? 10 : articles.length)
.map(async (item) => ({
title: item.article.headline,
author: item.article.authors.length > 0 ? item.article.authors.map((x) => x.name).toString() : item.article.byline,
category: item.article.channels.filter((x) => !x.homepage).map((x) => x.name),
description: await getFullText(item.article.slug),
link: resolve_url('https://theinitium.com', item.article.url),
pubDate: item.article.date,
updated: item.article.updated,
// 如果遇到编辑部漏录入情况,则给uuid做个手脚,以便阅读器到时重抓。
guid: (await getFullText(item.article.slug)).endsWith('内容为空,请稍后再来') ? item.article.uuid + '-I-am-empty' : item.article.uuid,
}))
.map(async (item) => {
const description = await getFullText(item.article.slug);
return {
title: item.article.headline,
author: item.article.authors.length > 0 ? item.article.authors.map((x) => x.name).toString() : item.article.byline,
category: item.article.channels.filter((x) => !x.homepage).map((x) => x.name),
description,
link: resolve_url('https://theinitium.com', item.article.url),
pubDate: new Date(fixDate(item.article.date)),
updated: new Date(fixDate(item.article.updated)),
// 如果遇到编辑部漏录入情况,则给uuid做个手脚,以便阅读器到时重抓。
guid: description.endsWith('内容为空,请稍后再来') ? item.article.uuid + '-I-am-empty' : item.article.uuid,
};
})
);
ctx.state.data = {