From 77b07b3b47101263cb2a2734b44e4daa0eb7edb6 Mon Sep 17 00:00:00 2001 From: HappyZhu99 <52676282+HappyZhu99@users.noreply.github.com> Date: Thu, 30 Oct 2025 14:31:31 +0800 Subject: [PATCH] feat(router/aiaa): rebuild rss from official (#20390) * feature(route/aiaa): new router added * feature(router/aiaa): rebuild rss from official * feature(route/aiaa): new to old pudate list with preprint and current issue * feature(route/aiaa): fix example * feat(route/aiaa): fix path * feat(route/aiaa): fix path * feat(route/aiaa): reuse DataItem and other optimization * delete empty file * fix namespace --- lib/routes/aiaa/journal.ts | 65 ++++++++++++++++++++++++++++++++++++ lib/routes/aiaa/namespace.ts | 7 ++++ 2 files changed, 72 insertions(+) create mode 100644 lib/routes/aiaa/journal.ts create mode 100644 lib/routes/aiaa/namespace.ts diff --git a/lib/routes/aiaa/journal.ts b/lib/routes/aiaa/journal.ts new file mode 100644 index 000000000..4ab11594a --- /dev/null +++ b/lib/routes/aiaa/journal.ts @@ -0,0 +1,65 @@ +import { DataItem, Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; +import { load } from 'cheerio'; + +export const route: Route = { + name: 'ASR Articles', + maintainers: ['HappyZhu99'], + categories: ['journal'], + path: '/journal/:journalID', + parameters: { + journalID: 'journal ID, can be found in the URL', + }, + example: '/aiaa/journal/aiaaj', + handler, +}; + +async function handler(ctx) { + const id = ctx.req.param('journalID'); + + const baseUrl = 'https://arc.aiaa.org'; + const rssUrl = `${baseUrl}/action/showFeed?type=etoc&feed=rss&jc=${id}`; + + const pageResponse = await ofetch(rssUrl); + + const $ = load(pageResponse, { + xml: { + xmlMode: true, + }, + }); + + const channelTitle = $('title').first().text().replace(': Table of Contents', ''); + + const imageUrl = $('image url').text(); + const items: DataItem[] = $('item') + .toArray() + .map((element) => { + const $item = $(element); + const title = $item.find(String.raw`dc\:title`).text(); + const link = $item.find('link').text() || ''; + const description = $item.find('description').text() || ''; + const pubDate = parseDate($item.find(String.raw`dc\:date`).text() || ''); + const authors = $item + .find(String.raw`dc\:creator`) + .toArray() + .map((authorElement) => $(authorElement).text()); + const author = authors.join(', '); + + return { + title, + link, + description, + pubDate, + author, + } satisfies DataItem; + }); + + return { + title: `${channelTitle} | arc.aiaa.org`, + description: 'List of articles from both the latest and ahead of print issues.', + image: imageUrl, + link: `${baseUrl}/journal/${id}`, + item: items, + }; +} diff --git a/lib/routes/aiaa/namespace.ts b/lib/routes/aiaa/namespace.ts new file mode 100644 index 000000000..f89d01ea9 --- /dev/null +++ b/lib/routes/aiaa/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'AIAA Aerospace Research Central', + url: 'arc.aiaa.org', + lang: 'en', +};