From 3e7cb6d845e82ec534fbc04527d6e36856c69d8f Mon Sep 17 00:00:00 2001 From: Bubu <43925055+p3psi-boo@users.noreply.github.com> Date: Thu, 26 Dec 2024 22:21:32 +0800 Subject: [PATCH] feat(route): add tiddlywiki releases (#17979) --- lib/routes/tiddlywiki/namespace.ts | 8 +++ lib/routes/tiddlywiki/releases.ts | 84 ++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 lib/routes/tiddlywiki/namespace.ts create mode 100644 lib/routes/tiddlywiki/releases.ts diff --git a/lib/routes/tiddlywiki/namespace.ts b/lib/routes/tiddlywiki/namespace.ts new file mode 100644 index 00000000000000..b8b7742b8babd5 --- /dev/null +++ b/lib/routes/tiddlywiki/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'TiddlyWiki', + url: 'tiddlywiki.com', + description: '', + lang: 'en', +}; diff --git a/lib/routes/tiddlywiki/releases.ts b/lib/routes/tiddlywiki/releases.ts new file mode 100644 index 00000000000000..cbc9174a602817 --- /dev/null +++ b/lib/routes/tiddlywiki/releases.ts @@ -0,0 +1,84 @@ +import { Route } from '@/types'; + +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/releases', + categories: ['program-update'], + example: '/tiddlywiki/releases', + url: 'tiddlywiki.com', + name: 'Releases', + maintainers: ['p3psi-boo'], + radar: [ + { + source: ['github.com/TiddlyWiki/TiddlyWiki5'], + target: '/releases', + }, + { + source: ['tiddlywiki.com'], + target: '/releases', + }, + ], + handler, +}; + +async function handler() { + const tagListUrl = 'https://github.com/TiddlyWiki/TiddlyWiki5/releases.atom'; + + const response = await got({ + method: 'get', + url: tagListUrl, + }); + + const $ = load(response.data); + + const alist = $('entry'); + + const versionList = alist + .toArray() + .map((item) => { + item = $(item); + const text = item.find('title').text(); + const date = item.find('updated').text(); + // 使用正则提取 v5.3.6 格式 + const version = text.match(/v\d+\.\d+\.\d+/)?.[0]; + return { + version, + pubDate: parseDate(date), + }; + }) + .filter((item) => item.version); + + const items = await Promise.all( + versionList.map((item) => { + const _version = item.version.slice(1); + const url = `https://tiddlywiki.com/static/Release%2520${_version}.html`; + return cache.tryGet(url, async () => { + const response = await got({ + method: 'get', + url, + }); + + const $ = load(response.data); + + const description = $('.tc-tiddler-body').html(); + + return { + title: item.version, + link: url, + pubDate: item.pubDate, + description, + }; + }); + }) + ); + + return { + title: 'TiddlyWiki Releases', + link: 'https://tiddlywiki.com/static/Releases.html', + item: items, + }; +}