kopia lustrzana https://github.com/badgen/badgen.net
style(pub): merge `dart-platform` & `flutter-platform` handlers (#496)
Co-authored-by: Amio Jin <amio.cn@gmail.com>pull/499/head^2
rodzic
6741d951b7
commit
3aec694e48
25
api/pub.ts
25
api/pub.ts
|
@ -82,24 +82,12 @@ async function webHandler({ topic, pkg }: PathArgs) {
|
|||
const html = await fetchPage(pkg)
|
||||
|
||||
switch (topic) {
|
||||
case 'dart-platform': {
|
||||
const platforms = [...html.matchAll(/class="tag-badge-sub" title="[^"]*?\bDart\b[^"]*?">([^<]+)<\//ig)]
|
||||
.map(match => match[1].trim())
|
||||
.join(' | ')
|
||||
|
||||
return {
|
||||
subject: 'dart',
|
||||
status: platforms || 'not supported',
|
||||
color: platforms ? 'blue' : 'grey'
|
||||
}
|
||||
}
|
||||
case 'dart-platform':
|
||||
case 'flutter-platform': {
|
||||
const platforms = [...html.matchAll(/class="tag-badge-sub" title="[^"]*?\bFlutter\b[^"]*?">([^<]+)<\//ig)]
|
||||
.map(match => match[1].trim())
|
||||
.join(' | ')
|
||||
|
||||
const [subject] = topic.split('-')
|
||||
const platforms = parseBadgeGroup(subject, html).join(' | ')
|
||||
return {
|
||||
subject: 'flutter',
|
||||
subject,
|
||||
status: platforms || 'not supported',
|
||||
color: platforms ? 'blue' : 'grey'
|
||||
}
|
||||
|
@ -115,6 +103,11 @@ async function webHandler({ topic, pkg }: PathArgs) {
|
|||
}
|
||||
}
|
||||
|
||||
function parseBadgeGroup(title: string, html: string) {
|
||||
const reBadge = new RegExp(`class="tag-badge-sub" title="[^"]*?\\b${title}\\b[^"]*?">([^<]+)<\\/`, 'ig')
|
||||
return [...html.matchAll(reBadge)].map(match => match[1].trim())
|
||||
}
|
||||
|
||||
async function fetchPage(pkg: string) {
|
||||
const resp = await got(`packages/${pkg}`, { followRedirect: false, prefixUrl: PUB_REPO_URL })
|
||||
if (resp.headers.location) {
|
||||
|
|
Ładowanie…
Reference in New Issue