feat: migrate /hackage badges, and fixes #585 (#600)

* feat: migrate /pypi badges

* feat: migrate /hackage badges

* chore: add comments for cabalfile compability
pull/601/head
Amio Jin 2023-06-10 11:11:10 +08:00 zatwierdzone przez GitHub
rodzic 34a019ab34
commit d7adf406b8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 17 dodań i 10 usunięć

Wyświetl plik

@ -20,7 +20,6 @@ export const liveBadgeList = [
'packagist', 'packagist',
'rubygems', 'rubygems',
'apm', 'apm',
'hackage',
'vs-marketplace', 'vs-marketplace',
'melpa', 'melpa',
'maven', 'maven',

Wyświetl plik

@ -2,6 +2,7 @@ import staticBadge from '../pages/api/static'
import github from '../pages/api/github' import github from '../pages/api/github'
import npm from '../pages/api/npm' import npm from '../pages/api/npm'
import chromeWebStore from '../pages/api/chrome-web-store' import chromeWebStore from '../pages/api/chrome-web-store'
import hackage from '../pages/api/hackage'
import pypi from '../pages/api/pypi' import pypi from '../pages/api/pypi'
import runkit from '../pages/api/runkit' import runkit from '../pages/api/runkit'
import winget from '../pages/api/winget' import winget from '../pages/api/winget'
@ -12,6 +13,7 @@ export default {
github: github.meta, github: github.meta,
npm: npm.meta, npm: npm.meta,
chromeWebStore: chromeWebStore.meta, chromeWebStore: chromeWebStore.meta,
hackage: hackage.meta,
pypi: pypi.meta, pypi: pypi.meta,
runkit: runkit.meta, runkit: runkit.meta,
winget: winget.meta, winget: winget.meta,

Wyświetl plik

@ -45,6 +45,7 @@ const nextConfig = {
'/github', '/github',
'/npm', '/npm',
'/chrome-web-store', '/chrome-web-store',
'/hackage',
'/pypi', '/pypi',
'/runkit', '/runkit',
'/winget', '/winget',

Wyświetl plik

@ -1,6 +1,6 @@
import got from '../libs/got' import got from '../../libs/got'
import { version as v, versionColor } from '../libs/utils' import { version as v, versionColor } from '../../libs/utils'
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler' import { createBadgenHandler, PathArgs } from '../../libs/create-badgen-handler-next'
export default createBadgenHandler({ export default createBadgenHandler({
title: 'Hackage', title: 'Hackage',
@ -32,14 +32,23 @@ async function handler ({ topic, pkg }: PathArgs) {
status: license, status: license,
color: 'blue' color: 'blue'
} }
default:
return {
subject: 'hackage',
status: 'unknown topic',
color: 'grey'
}
} }
} }
// Naive implementation (only parse meta blocks) // Naive implementation (only parse meta blocks)
const parseCabalFile = raw => { const parseCabalFile = raw => {
return raw.match(/[\w-]+:.+\S+$/gm).reduce((accu, line) => { // this regex needs to support both v1 and v2 for cabalfile
const cabalMeta = raw.match(/[\w-]+:.+\S+$/gm).reduce((accu, line) => {
const [key, value] = line.split(':') const [key, value] = line.split(':')
accu[key] = value.trim() accu[key.toLowerCase()] = value.trim()
return accu return accu
}, {}) }, {})
return cabalMeta
} }

Wyświetl plik

@ -110,10 +110,6 @@
"source": "/gitter/:match*", "source": "/gitter/:match*",
"destination": "https://v2022.badgen.net/gitter/:match*" "destination": "https://v2022.badgen.net/gitter/:match*"
}, },
{
"source": "/hackage/:match*",
"destination": "https://v2022.badgen.net/hackage/:match*"
},
{ {
"source": "/haxelib/:match*", "source": "/haxelib/:match*",
"destination": "https://v2022.badgen.net/haxelib/:match*" "destination": "https://v2022.badgen.net/haxelib/:match*"