feat: migrate badge generator /xo

pull/579/head
Amio 2023-02-05 19:20:03 +08:00
rodzic 4b7093a711
commit eafedd06bf
5 zmienionych plików z 94 dodań i 117 usunięć

Wyświetl plik

@ -1,38 +0,0 @@
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
export default createBadgenHandler({
title: 'Static',
examples: {
'/badge/Swift/4.2/orange': 'swift version',
'/badge/license/MIT/blue': 'license MIT',
'/badge/chat/on%20gitter/cyan': 'chat on gitter',
'/badge/stars/★★★★☆': 'star rating',
'/badge/become/a%20patron/F96854': 'patron',
'/badge/code%20style/standard/f2a': 'code style: standard'
},
handlers: {
'/badge/:label/:status': handler,
'/badge/:label/:status/:color': handler
}
})
async function handler ({ label, status, color }: PathArgs) {
return {
subject: label,
status,
color
}
}
// {
// title: 'With Options',
// examples: {
// '/badge/icon/github?icon=github': 'use builtin icon',
// '/badge/github/github?icon': 'use builtin icon (by subject)',
// '/badge/jQuery/powered?icon=https://simpleicons.now.sh/jquery/fff': 'use external icon',
// '/badge/icon/github?label=custom%20label': 'custom label',
// '/badge/icon/github?label': 'disable label',
// '/badge/github/github?icon&label': 'use icon, disable label',
// '/badge/platform/ios,macos,tvos?list=|': 'list (custom seprator)'
// }
// }

Wyświetl plik

@ -1,83 +1,83 @@
import path from 'path'
import staticBadges from '../api/badge'
import staticBadges from '../pages/api/static'
const rel = (...args) => path.resolve(__dirname, ...args)
// sort live badge manually
export const liveBadgeList = [
// source control
'github',
'gitlab',
// release registries
'npm',
'david',
'packagephobia',
'bundlephobia',
'crates',
'docker',
'homebrew',
'chrome-web-store',
'amo',
'pypi',
'nuget',
'packagist',
'rubygems',
'apm',
'hackage',
'vs-marketplace',
'melpa',
'maven',
'cocoapods',
'haxelib',
'opam',
'cpan',
'cran',
'ctan',
'dub',
'elm-package',
'scoop',
'winget',
'f-droid',
'pub',
'shards',
'wapm',
'open-vsx',
'snapcraft',
// CI
'travis',
'circleci',
'appveyor',
'codecov',
'codacy',
'coveralls',
'codeclimate',
'azure-pipelines',
// quality & metrics
'snyk',
'lgtm',
'deepscan',
'uptime-robot',
'xo',
'badgesize',
'jsdelivr',
// social
'devrant',
'peertube',
'reddit',
// chat
'discord',
'gitter',
'matrix',
// utilities
'opencollective',
'keybase',
'twitter',
'mastodon',
'tidelift',
'jenkins',
'liberapay',
'runkit',
'https',
// // source control
// 'github',
// 'gitlab',
// // release registries
// 'npm',
// 'david',
// 'packagephobia',
// 'bundlephobia',
// 'crates',
// 'docker',
// 'homebrew',
// 'chrome-web-store',
// 'amo',
// 'pypi',
// 'nuget',
// 'packagist',
// 'rubygems',
// 'apm',
// 'hackage',
// 'vs-marketplace',
// 'melpa',
// 'maven',
// 'cocoapods',
// 'haxelib',
// 'opam',
// 'cpan',
// 'cran',
// 'ctan',
// 'dub',
// 'elm-package',
// 'scoop',
// 'winget',
// 'f-droid',
// 'pub',
// 'shards',
// 'wapm',
// 'open-vsx',
// 'snapcraft',
// // CI
// 'travis',
// 'circleci',
// 'appveyor',
// 'codecov',
// 'codacy',
// 'coveralls',
// 'codeclimate',
// 'azure-pipelines',
// // quality & metrics
// 'snyk',
// 'lgtm',
// 'deepscan',
// 'uptime-robot',
// 'xo',
// 'badgesize',
// 'jsdelivr',
// // social
// 'devrant',
// 'peertube',
// 'reddit',
// // chat
// 'discord',
// 'gitter',
// 'matrix',
// // utilities
// 'opencollective',
// 'keybase',
// 'twitter',
// 'mastodon',
// 'tidelift',
// 'jenkins',
// 'liberapay',
// 'runkit',
// 'https',
]
export async function loadBadgeMeta () {

Wyświetl plik

@ -10,6 +10,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'
import type { BadgenParams } from './types'
export type PathArgs = NonNullable<ReturnType<typeof matchRoute>>
export type BadgenResult = Promise<BadgenParams>
export interface BadgenServeConfig {
title: string;
@ -19,7 +20,7 @@ export interface BadgenServeConfig {
}
export function createBadgenHandler (badgenServerConfig: BadgenServeConfig) {
const { handlers } = badgenServerConfig
const { handlers, title, help, examples } = badgenServerConfig
async function nextHandler (req: NextApiRequest, res: NextApiResponse) {
let { pathname } = new URL(req.url || '/', `http://${req.headers.host}`)
@ -51,6 +52,8 @@ export function createBadgenHandler (badgenServerConfig: BadgenServeConfig) {
return res.status(404).end()
}
nextHandler.meta = { title, examples, help, handlers }
return nextHandler
}

Wyświetl plik

@ -31,7 +31,10 @@ const nextConfig = {
{ source: '/static', destination: '/api/static' },
{ source: '/badge/:path*', destination: '/api/static' },
{ source: '/badge', destination: '/api/static' }
{ source: '/badge', destination: '/api/static' },
{ source: '/xo/:path*', destination: '/api/xo' },
{ source: '/xo', destination: '/api/xo' },
]
},
}

Wyświetl plik

@ -1,5 +1,7 @@
import got from '../libs/got'
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
import got from '../../libs/got'
import { createBadgenHandler } from '../../libs/create-badgen-handler-next'
import type { PathArgs, BadgenResult } from '../../libs/create-badgen-handler-next'
export default createBadgenHandler({
title: 'XO',
@ -22,7 +24,7 @@ const getIndent = space => {
return `${space} spaces`
}
async function handler ({ topic, scope, name }: PathArgs) {
async function handler ({ topic, scope, name }: PathArgs): BadgenResult {
const pkg = scope ? `${scope}/${name}` : name
const endpoint = `https://cdn.jsdelivr.net/npm/${pkg}/package.json`
const data = await got(endpoint).json<any>()
@ -61,5 +63,12 @@ async function handler ({ topic, scope, name }: PathArgs) {
status: semicolon ? 'enabled' : 'disabled',
color: '5ED9C7'
}
default:
return {
subject: 'XO',
status: 'unknown topic',
color: 'red'
}
}
}