-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add tiddlywiki releases (#17979)
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |