-
Notifications
You must be signed in to change notification settings - Fork 10.1k
feat: add aiera.com.cn 新智元 RSS route #22118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
05d06b1
7d2aaa3
ae34cd0
5bcb15d
ad40f54
fde16c3
14d218a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type { Route } from '@/types'; | ||
| import cache from '@/utils/cache'; | ||
| import got from '@/utils/got'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/latest', | ||
| categories: ['new-media'], | ||
| example: '/aiera/latest', | ||
| url: 'aiera.com.cn', | ||
| name: '最新文章', | ||
| maintainers: ['panqingjie00'], | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['aiera.com.cn'], | ||
| target: '/latest', | ||
| }, | ||
| ], | ||
| handler, | ||
| }; | ||
|
|
||
| async function handler(ctx) { | ||
Check failureCode scanning / oxlint eslint(no-unused-vars) Error
Parameter 'ctx' is declared but never used. Unused parameters should start with a '_'.
Consider removing this parameter. |
||
| const response = await cache.tryGet('aiera:latest', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't cache the response as it will refresh the cache duration on each request. This means the entries won't be updated once it's cached. |
||
| const { data } = await got('https://aiera.com.cn/wp-json/wp/v2/posts', { | ||
| searchParams: { | ||
| per_page: 20, | ||
| _embed: '', | ||
| }, | ||
| }); | ||
| return data; | ||
| }); | ||
|
|
||
| if (!Array.isArray(response)) { | ||
Check failureCode scanning / oxlint unicorn(prefer-type-error) Error
Prefer throwing a TypeError over a generic Error after a type checking if-statement
Change to throw new TypeError(...) |
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| throw new Error('Invalid API response'); | ||
| } | ||
|
|
||
| const items = response.map((item) => ({ | ||
| title: item.title.rendered, | ||
| description: item.content.rendered, | ||
| pubDate: parseDate(item.date_gmt), | ||
| link: item.link, | ||
| guid: item.guid.rendered, | ||
| author: item._embedded?.author?.[0]?.name, | ||
| })); | ||
|
|
||
| return { | ||
| title: '新智元 - 最新文章', | ||
| link: 'https://aiera.com.cn', | ||
| description: '新智元最新 AI 新闻资讯', | ||
| language: 'zh-CN', | ||
| item: items, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: '新智元', | ||
| url: 'aiera.com.cn', | ||
| lang: 'zh-CN', | ||
| description: '新智元 - AI 新闻资讯平台', | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.