Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions lib/routes/aiera/latest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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() {
const response = await cache.tryGet('aiera:latest', async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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)) {
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
throw new TypeError('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',
image: 'https://aiera.com.cn/wp-content/uploads/2025/01/%E6%96%B0%E6%99%BA%E5%85%83%E7%BD%91%E7%AB%99logo-150x150.png',
item: items,
};
}
8 changes: 8 additions & 0 deletions lib/routes/aiera/namespace.ts
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 新闻资讯平台',
};