style(pub): merge `dart-platform` & `flutter-platform` handlers (#496)

Co-authored-by: Amio Jin <amio.cn@gmail.com>
pull/499/head^2
Dario Vladović 2021-02-14 03:37:04 +01:00 zatwierdzone przez GitHub
rodzic 6741d951b7
commit 3aec694e48
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 9 dodań i 16 usunięć

Wyświetl plik

@ -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) {