From d7adf406b836a51f5c4735519165700c5e07a25a Mon Sep 17 00:00:00 2001 From: Amio Jin Date: Sat, 10 Jun 2023 11:11:10 +0800 Subject: [PATCH] feat: migrate /hackage badges, and fixes #585 (#600) * feat: migrate /pypi badges * feat: migrate /hackage badges * chore: add comments for cabalfile compability --- libs/badge-list.ts | 1 - libs/badge-list2.ts | 2 ++ next.config.js | 1 + {api- => pages/api}/hackage.ts | 19 ++++++++++++++----- vercel.json | 4 ---- 5 files changed, 17 insertions(+), 10 deletions(-) rename {api- => pages/api}/hackage.ts (64%) diff --git a/libs/badge-list.ts b/libs/badge-list.ts index b018293..b0a5d7d 100644 --- a/libs/badge-list.ts +++ b/libs/badge-list.ts @@ -20,7 +20,6 @@ export const liveBadgeList = [ 'packagist', 'rubygems', 'apm', - 'hackage', 'vs-marketplace', 'melpa', 'maven', diff --git a/libs/badge-list2.ts b/libs/badge-list2.ts index 53aee9f..e9ced27 100644 --- a/libs/badge-list2.ts +++ b/libs/badge-list2.ts @@ -2,6 +2,7 @@ import staticBadge from '../pages/api/static' import github from '../pages/api/github' import npm from '../pages/api/npm' import chromeWebStore from '../pages/api/chrome-web-store' +import hackage from '../pages/api/hackage' import pypi from '../pages/api/pypi' import runkit from '../pages/api/runkit' import winget from '../pages/api/winget' @@ -12,6 +13,7 @@ export default { github: github.meta, npm: npm.meta, chromeWebStore: chromeWebStore.meta, + hackage: hackage.meta, pypi: pypi.meta, runkit: runkit.meta, winget: winget.meta, diff --git a/next.config.js b/next.config.js index a7886b3..95520f2 100644 --- a/next.config.js +++ b/next.config.js @@ -45,6 +45,7 @@ const nextConfig = { '/github', '/npm', '/chrome-web-store', + '/hackage', '/pypi', '/runkit', '/winget', diff --git a/api-/hackage.ts b/pages/api/hackage.ts similarity index 64% rename from api-/hackage.ts rename to pages/api/hackage.ts index 8d55658..5cbd9fe 100644 --- a/api-/hackage.ts +++ b/pages/api/hackage.ts @@ -1,6 +1,6 @@ -import got from '../libs/got' -import { version as v, versionColor } from '../libs/utils' -import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler' +import got from '../../libs/got' +import { version as v, versionColor } from '../../libs/utils' +import { createBadgenHandler, PathArgs } from '../../libs/create-badgen-handler-next' export default createBadgenHandler({ title: 'Hackage', @@ -32,14 +32,23 @@ async function handler ({ topic, pkg }: PathArgs) { status: license, color: 'blue' } + default: + return { + subject: 'hackage', + status: 'unknown topic', + color: 'grey' + } } } // Naive implementation (only parse meta blocks) 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(':') - accu[key] = value.trim() + accu[key.toLowerCase()] = value.trim() return accu }, {}) + + return cabalMeta } diff --git a/vercel.json b/vercel.json index b60e8f2..163b6a3 100644 --- a/vercel.json +++ b/vercel.json @@ -110,10 +110,6 @@ "source": "/gitter/:match*", "destination": "https://v2022.badgen.net/gitter/:match*" }, - { - "source": "/hackage/:match*", - "destination": "https://v2022.badgen.net/hackage/:match*" - }, { "source": "/haxelib/:match*", "destination": "https://v2022.badgen.net/haxelib/:match*"