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

Wyświetl plik

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

Wyświetl plik

@ -7,82 +7,80 @@ const rel = (...args) => path.resolve(__dirname, ...args)
export const liveBadgeList = [ export const liveBadgeList = [
// // source control // // source control
// 'github', // 'github',
// 'gitlab', 'gitlab',
// // release registries // release registries
// 'npm', 'npm',
// 'david', 'david',
// 'packagephobia', 'packagephobia',
// 'bundlephobia', 'bundlephobia',
// 'crates', 'crates',
// 'docker', 'docker',
// 'homebrew', 'homebrew',
// 'chrome-web-store', 'chrome-web-store',
// 'amo', 'amo',
// 'pypi', 'pypi',
// 'nuget', 'nuget',
// 'packagist', 'packagist',
// 'rubygems', 'rubygems',
// 'apm', 'apm',
// 'hackage', 'hackage',
// 'vs-marketplace', 'vs-marketplace',
// 'melpa', 'melpa',
// 'maven', 'maven',
// 'cocoapods', 'cocoapods',
// 'haxelib', 'haxelib',
// 'opam', 'opam',
// 'cpan', 'cpan',
// 'cran', 'cran',
// 'ctan', 'ctan',
// 'dub', 'dub',
// 'elm-package', 'elm-package',
// 'scoop', 'scoop',
// 'winget', 'f-droid',
// 'f-droid', 'pub',
// 'pub', 'shards',
// 'shards', 'wapm',
// 'wapm', 'open-vsx',
// 'open-vsx', 'snapcraft',
// 'snapcraft', // CI
// // CI 'travis',
// 'travis', 'circleci',
// 'circleci', 'appveyor',
// 'appveyor', 'codecov',
// 'codecov', 'codacy',
// 'codacy', 'coveralls',
// 'coveralls', 'codeclimate',
// 'codeclimate', 'azure-pipelines',
// 'azure-pipelines', // quality & metrics
// // quality & metrics 'snyk',
// 'snyk', 'lgtm',
// 'lgtm', 'deepscan',
// 'deepscan', 'uptime-robot',
// 'uptime-robot', 'badgesize',
// 'xo', 'jsdelivr',
// 'badgesize', // social
// 'jsdelivr', 'devrant',
// // social 'peertube',
// 'devrant', 'reddit',
// 'peertube', // chat
// 'reddit', 'discord',
// // chat 'gitter',
// 'discord', 'matrix',
// 'gitter', // utilities
// 'matrix', 'opencollective',
// // utilities 'keybase',
// 'opencollective', 'twitter',
// 'keybase', 'mastodon',
// 'twitter', 'tidelift',
// 'mastodon', 'jenkins',
// 'tidelift', 'liberapay',
// 'jenkins', 'runkit',
// 'liberapay', 'https',
// 'runkit',
// 'https',
] ]
export async function loadBadgeMeta () { export async function loadBadgeMeta () {
const liveBadgeExamples = await Promise.all(liveBadgeList.map(async id => { 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 const { title, examples, handlers } = mod.default.meta
return { return {

Wyświetl plik

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