feat: include legacy badge examples in badge builder

pull/579/head
Amio 2023-03-18 17:58:22 +08:00
rodzic a1ddd5d253
commit 7b85c086b1
4 zmienionych plików z 95 dodań i 81 usunięć

Wyświetl plik

@ -1,17 +1,33 @@
import badgeList from '../public/.meta/badge-list.json'
import badgeListLegacy from '../public/.meta/badges.json'
// const examples = [...badgeList.live, ...badgeList.static].reduce((accu, curr) => {
// return (accu as any).concat(Object.entries(curr.examples))
// }, [] as [string, string][])
type Examples = [string, string][]
type BadgeExamples = {
[pathname: string]: string
}
type BadgeList = {
[id: string]: {
title: string;
examples: BadgeExamples;
}
}
function extractExampleList (badgeList): Examples {
const examples = []
const examples = extractExampleList(badgeList)
function extractExampleList (badgeList: BadgeList): BadgeExamples {
let examples = {}
Object.entries(badgeList).forEach((x) => {
console.log(x)
// Object.entries(meta?.examples)
examples = { ...examples, ...x[1].examples }
})
// Also apply legacy examples
badgeListLegacy.live.forEach((x) => {
examples = { ...examples, ...x.examples }
})
return examples
@ -24,13 +40,11 @@ interface BuilderHelperProps {
}
export default function BuilderHelper ({ badgeURL, onSelect }: BuilderHelperProps) {
console.log(2333)
if (badgeURL.length < 2) {
return <div className='helper' />
}
const examples = extractExampleList(badgeList)
const matched = examples.filter(eg => eg[0].includes(badgeURL))
const matched = Object.entries(examples).filter(eg => eg[0].includes(badgeURL))
const hints = matched.length === 1 && matched[0][0] === '/' + badgeURL ? null : (
<div className='suggestions'>

Wyświetl plik

@ -27,7 +27,7 @@ export default function BuilderHints ({ focus, badgeURL }) {
overflow: visible;
width: 100%;
left: -147px;
height: 200px;
/* height: 200px; */
transition: all 200ms cubic-bezier(0.215, 0.61, 0.355, 1);
}
.hint a {

Wyświetl plik

@ -7,82 +7,80 @@ const rel = (...args) => path.resolve(__dirname, ...args)
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',
'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',
'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',
'badgesize',
'jsdelivr',
// social
'devrant',
'peertube',
'reddit',
// chat
'discord',
'gitter',
'matrix',
// utilities
'opencollective',
'keybase',
'twitter',
'mastodon',
'tidelift',
'jenkins',
'liberapay',
'runkit',
'https',
]
export async function loadBadgeMeta () {
const liveBadgeExamples = await Promise.all(liveBadgeList.map(async id => {
const mod = await import(rel('../api', id))
const mod = await import(rel('../api-', id))
const { title, examples, handlers } = mod.default.meta
return {

Wyświetl plik

@ -6,11 +6,13 @@ import BadgeList2 from '../libs/badge-list2'
const rel = (...args) => path.resolve(__dirname, ...args)
;(async function main () {
// old list
const badgeMeta = await loadBadgeMeta()
await fse.outputJson(rel('../public/.meta/badges.json'), badgeMeta, {
spaces: 2
})
// new list
await fse.outputJson(rel('../public/.meta/badge-list.json'), BadgeList2, {
spaces: 2
})