feat: added iDaily 每日环球视野 (#6502)

This commit is contained in:
zphw 2020-12-24 01:53:05 +08:00 committed by GitHub
parent 162dadb12c
commit abcf932555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -256,6 +256,12 @@ Tag
<Route author="loganrockmore" example="/grubstreet" path="/grubstreet" />
## iDaily 每日环球视野
### 今日 Timeline
<Route author="zphw" example="/idaily/today" path="/idaily/today" />
## iDownloadBlog
### blog

View File

@ -3733,6 +3733,9 @@ router.get('/dayone/blog', require('./routes/dayone/blog'));
// 滴答清单
router.get('/dida365/habit/checkins', require('./routes/dida365/habit-checkins'));
// iDaily 每日环球视野
router.get('/idaily/today', require('./routes/idaily/index'));
// 北屋
router.get('/northhouse/:category?', require('./routes/northhouse/index'));

View File

@ -0,0 +1,28 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'http://idaily-cdn.idailycdn.com/api/list/v3/iphone/zh-hans?page=1&ver=iphone',
});
const data = response.data;
let dataToday = data.filter((item) => item.pubdate_timestamp * 1000 >= new Date().getTime() - 86400000);
// leverage yesterday's items if today's not published yet
if (dataToday.length === 0) {
dataToday = data.filter((item) => item.pubdate_timestamp * 1000 >= new Date().getTime() - 86400000 * 2);
}
ctx.state.data = {
title: `iDaily 每日环球视野`,
description: 'iDaily 每日环球视野',
item: dataToday.map((item) => ({
title: item.ui_sets.caption_subtitle,
description: `<img src='${item.cover_landscape}'><br>${item.content}`,
pubDate: new Date(item.pubdate_timestamp * 1000).toUTCString(),
link: item.link_share,
})),
};
};