Skip to content

Commit

Permalink
feat(route): add tiddlywiki releases (#17979)
Browse files Browse the repository at this point in the history
  • Loading branch information
p3psi-boo authored Dec 26, 2024
1 parent 372904d commit 3e7cb6d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/routes/tiddlywiki/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: 'TiddlyWiki',
url: 'tiddlywiki.com',
description: '',
lang: 'en',
};
84 changes: 84 additions & 0 deletions lib/routes/tiddlywiki/releases.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}

0 comments on commit 3e7cb6d

Please sign in to comment.