forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add Yonhap News Agency route (DIYgod#17802)
* feat(route): add Yonhap New Agency route * Update lib/routes/yna/namespace.ts ---------
- Loading branch information
1 parent
103ef92
commit b12b135
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Route } from '@/types'; | ||
import parser from '@/utils/rss-parser'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import timezone from '@/utils/timezone'; | ||
|
||
export const route: Route = { | ||
path: '/:lang?/:channel?', | ||
categories: ['traditional-media'], | ||
example: '/yna/en/national', | ||
parameters: { | ||
lang: 'Language, see below, `ko` by default', | ||
channel: 'RSS Feed Channel, see below, `news` by default', | ||
}, | ||
features: { | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
requireConfig: false, | ||
}, | ||
name: 'News', | ||
maintainers: ['quiniapiezoelectricity'], | ||
handler, | ||
description: ` | ||
| Language | 한국어 | English | 简体中文 | 日本語 | عربي | Español | Français | | ||
| --------- | ------ | ------- | -------- | ------ | ------ | ------- | -------- | | ||
| \`:lang\` | \`ko\` | \`en\` | \`cn\` | \`jp\` | \`ar\` | \`es\` | \`fr\` | | ||
For a full list of RSS Feed Channels, please refer to the RSS feed page of the corresponding language | ||
| RSS Feed Page | | ||
| --------------------------------------------------------- | | ||
| [한국어](https://www.yna.co.kr/rss/index?site=footer_rss) | | ||
| [English](https://en.yna.co.kr/channel/index) | | ||
| [简体中文](https://cn.yna.co.kr/channel/index) | | ||
| [日本語](https://jp.yna.co.kr/channel/index) | | ||
| [عربي](https://ar.yna.co.kr/channel/index) | | ||
| [Español](https://sp.yna.co.kr/channel/index) | | ||
| [Français](https://fr.yna.co.kr/channel/index) | | ||
:::tip | ||
For example, the path for the RSS feed url https://www.yna.co.kr/rss/economy.xml and https://cn.yna.co.kr/RSS/news.xml would be \`/ko/economy\` and \`/cn/news\` respectively. | ||
::: | ||
`, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const lang = ctx.req.param('lang') ?? 'ko'; | ||
const channel = ctx.req.param('channel') ?? 'news'; | ||
let url; | ||
switch (lang) { | ||
case 'ko': | ||
url = `https://www.yna.co.kr/rss/${channel}.xml`; | ||
break; | ||
default: | ||
url = `https://${lang}.yna.co.kr/RSS/${channel}.xml`; | ||
break; | ||
} | ||
|
||
const feed = await parser.parseURL(url); | ||
const items = await Promise.all( | ||
feed.items.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
item.pubDate = lang === 'ko' ? parseDate(item.pubDate) : timezone(parseDate(item.pubDate), +9); // Timezone is only included in the pubDate of the Korean language RSS | ||
const response = await got(item.link); | ||
const $ = load(response.data); | ||
item.author = | ||
item.creator ?? | ||
$('.tit-name') | ||
.toArray() | ||
.map((c) => $(c).text()) | ||
.join(', '); | ||
const article = $('article.story-news'); | ||
article.find('.related-group').remove(); | ||
article.find('.writer-zone01').remove(); | ||
item.description = article.html(); | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: feed.title, | ||
link: feed.link, | ||
description: feed.description, | ||
language: feed.language ?? lang, | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'Yonhap News Agency', | ||
url: 'yna.co.kr', | ||
lang: 'ko', | ||
zh: { | ||
name: '韩联社', | ||
} | ||
}; |