fix(route): iDaily每日环球视野 (#14652)
* fix(route): iDaily每日环球视野 * fix: js to ts * fix typo
This commit is contained in:
parent
130b11224e
commit
8c9c45232f
|
|
@ -1591,7 +1591,7 @@ router.get('/dida365/habit/checkins', lazyloadRouteHandler('./routes/dida365/hab
|
|||
router.get('/ditto/changes/:type?', lazyloadRouteHandler('./routes/ditto/changes'));
|
||||
|
||||
// iDaily 每日环球视野
|
||||
router.get('/idaily/today', lazyloadRouteHandler('./routes/idaily/index'));
|
||||
// router.get('/idaily/today', lazyloadRouteHandler('./routes/idaily/index'));
|
||||
|
||||
// Oak Ridge National Laboratory
|
||||
router.get('/ornl/news', lazyloadRouteHandler('./routes/ornl/news'));
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
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.filter((item) => item.ui_sets && item.ui_sets.caption_subtitle).slice(0, 15);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `iDaily 每日环球视野`,
|
||||
description: 'iDaily 每日环球视野',
|
||||
item: data.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,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { art } from '@/utils/render';
|
||||
import * as path from 'node:path';
|
||||
|
||||
export default async (ctx) => {
|
||||
const { language = 'zh-hans' } = ctx.req.param();
|
||||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 100;
|
||||
|
||||
const rootUrl = 'https://idaily-cdn.idailycdn.com';
|
||||
const apiUrl = new URL(`api/list/v3/iphone/${language}`, rootUrl).href;
|
||||
const currentUrl = 'https://idai.ly';
|
||||
|
||||
const { data: response } = await got(apiUrl);
|
||||
|
||||
const items = response
|
||||
.filter((item) => item.ui_sets?.caption_subtitle)
|
||||
.slice(0, limit)
|
||||
.map((item) => {
|
||||
const image = item.ui_sets?.cover_landscape_hd_4k ?? item.cover_landscape_hd;
|
||||
|
||||
return {
|
||||
title: `${item.ui_sets?.caption_subtitle} - ${item.title}`,
|
||||
link: item.link_share,
|
||||
description: art(path.join(__dirname, 'templates/description.art'), {
|
||||
images: image
|
||||
? [
|
||||
{
|
||||
src: image,
|
||||
alt: item.ui_sets?.caption_subtitle ?? item.title,
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
intro: item.content,
|
||||
}),
|
||||
author: item.location,
|
||||
category: item.tags.map((c) => c.name),
|
||||
guid: `idaily-${item.guid}`,
|
||||
pubDate: parseDate(item.pubdate_timestamp, 'X'),
|
||||
updated: parseDate(item.lastupdate_timestamp, 'X'),
|
||||
enclosure_url: image,
|
||||
enclosure_type: `image/${image.split(/\./).pop()}`,
|
||||
};
|
||||
});
|
||||
|
||||
const { data: currentResponse } = await got(currentUrl);
|
||||
|
||||
const $ = load(currentResponse);
|
||||
|
||||
const title = $('title').text();
|
||||
const image = new URL('img/idaily/logo_2x.png', currentUrl).href;
|
||||
|
||||
ctx.set('data', {
|
||||
item: items,
|
||||
title,
|
||||
link: currentUrl,
|
||||
description: $('meta[name="description"]').prop('content'),
|
||||
language: 'zh',
|
||||
image,
|
||||
subtitle: $('meta[name="keywords"]').prop('content'),
|
||||
author: title.split(/\s/)[0],
|
||||
allowEmpty: true,
|
||||
});
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export default {
|
||||
'/:language?': ['zphw', 'nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
export default {
|
||||
'idai.ly': {
|
||||
_name: 'iDaily',
|
||||
'.': [
|
||||
{
|
||||
title: '每日环球视野',
|
||||
docs: 'https://docs.rsshub.app/routes/new-media#idaily-mei-ri-huan-qiu-shi-ye',
|
||||
source: ['/'],
|
||||
target: (_, url) => {
|
||||
url = new URL(url);
|
||||
const language = url.searchParams.get('lang');
|
||||
|
||||
return `/idaily${language ? `/${language}` : ''}`;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
export default (router) => {
|
||||
router.get('/today/:language?', './');
|
||||
router.get('/:language?', './');
|
||||
};
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{{ if images }}
|
||||
{{ each images image }}
|
||||
{{ if image?.src }}
|
||||
<figure>
|
||||
<img
|
||||
{{ if image.alt }}
|
||||
alt="{{ image.alt }}"
|
||||
{{ /if }}
|
||||
src="{{ image.src }}">
|
||||
</figure>
|
||||
{{ /if }}
|
||||
{{ /each }}
|
||||
{{ /if }}
|
||||
|
||||
{{ if intro }}
|
||||
<p>{{ intro }}</p>
|
||||
{{ /if }}
|
||||
|
|
@ -704,11 +704,15 @@
|
|||
|
||||
<Route author="nczitzk" example="/hkjunkcall" path="/hkjunkcall" anticrawler="1" />
|
||||
|
||||
## iDaily 每日环球视野 {#idaily-mei-ri-huan-qiu-shi-ye}
|
||||
## iDaily {#idaily}
|
||||
|
||||
### 今日 Timeline {#idaily-mei-ri-huan-qiu-shi-ye-jin-ri-timeline}
|
||||
### 每日环球视野 {#idaily-mei-ri-huan-qiu-shi-ye}
|
||||
|
||||
<Route author="zphw" example="/idaily/today" path="/idaily/today" />
|
||||
<Route author="zphw nczitzk" example="/idaily" path="/idaily/:language?" paramsDesc={['语言,见下表,默认为简体中文']} radar="1">
|
||||
| 简体中文 | 繁体中文 |
|
||||
| -------- | -------- |
|
||||
| zh-hans | zh-hant |
|
||||
</Route>
|
||||
|
||||
## iDownloadBlog {#idownloadblog}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue