From c65d8d6ae3430cfbaf97353aa2ab417eea426399 Mon Sep 17 00:00:00 2001 From: Tsung-Han Yu <14802181+johan456789@users.noreply.github.com> Date: Wed, 13 Aug 2025 02:21:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20Add=20=E8=8B=B1=E8=AA=9E?= =?UTF-8?q?=E4=B9=8B=E5=AE=B6=20-=20The=20Home=20of=20English=20feed=20(#1?= =?UTF-8?q?9814)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add feed for englishhome * fix: route issues - add namespace.ts - fix date parsing * fix: route name and description * refactor: use wordpress api * fix: remove CDATA section --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- lib/routes/englishhome/index.ts | 55 +++++++++++++++++++++++++++++ lib/routes/englishhome/namespace.ts | 6 ++++ 2 files changed, 61 insertions(+) create mode 100644 lib/routes/englishhome/index.ts create mode 100644 lib/routes/englishhome/namespace.ts diff --git a/lib/routes/englishhome/index.ts b/lib/routes/englishhome/index.ts new file mode 100644 index 000000000..d3f0a0968 --- /dev/null +++ b/lib/routes/englishhome/index.ts @@ -0,0 +1,55 @@ +import { Route, type Data } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/', + categories: ['blog'], + example: '/englishhome', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['englishhome.org/'], + }, + ], + name: '首頁', + maintainers: ['johan456789'], + handler, + description: '英語之家 - The Home of English 首頁', +}; + +async function handler() { + const rootUrl = 'https://englishhome.org'; + const apiUrl = `${rootUrl}/wp-json/wp/v2/posts?per_page=20&_embed=author,wp:term`; + + const data = await ofetch(apiUrl); + + const items = data.map((post) => ({ + title: post.title?.rendered, + description: post.content?.rendered ?? post.excerpt?.rendered ?? '', + link: post.link, + pubDate: parseDate(post.date_gmt ?? post.date), + author: post._embedded?.author?.[0]?.name, + category: Array.isArray(post._embedded?.['wp:term']) + ? post._embedded['wp:term'] + .flat() + .map((term: any) => term?.name) + .filter(Boolean) + : undefined, + })); + + return { + title: '英語之家 - The Home of English', + link: rootUrl, + language: 'zh-TW', + item: items, + } as Data; +} diff --git a/lib/routes/englishhome/namespace.ts b/lib/routes/englishhome/namespace.ts new file mode 100644 index 000000000..79268daaf --- /dev/null +++ b/lib/routes/englishhome/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '英語之家', + url: 'englishhome.org', +};