-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2d48f1
commit c098ab0
Showing
16 changed files
with
164 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
nav: components | ||
group: shields | ||
title: Docker | ||
order: 4 | ||
--- | ||
|
||
<code src="./index.tsx" inline></code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useControls, useCreateStore } from '@lobehub/ui'; | ||
import { folder } from 'leva'; | ||
import { memo, useMemo } from 'react'; | ||
|
||
import MarkdownStorybook from '@/components/MarkdownStorybook'; | ||
import { dockerShieldControlsPickList } from '@/const/dockerShieldControls'; | ||
import { genDockerShields } from '@/services/genDockerShield'; | ||
|
||
import { defaultControlsExtra } from './share'; | ||
|
||
const controls = defaultControlsExtra; | ||
const pickControls = { ['✅']: folder(dockerShieldControlsPickList, { collapsed: true }) }; | ||
|
||
const Docker = memo(() => { | ||
const store = useCreateStore(); | ||
|
||
const options = useControls(controls, { store }); | ||
const pickOptions = useControls(pickControls, { store }); | ||
|
||
const md = useMemo(() => genDockerShields(options, pickOptions), [options, pickOptions]); | ||
|
||
return <MarkdownStorybook levaStore={store}>{md.join('\n\n')}</MarkdownStorybook>; | ||
}); | ||
|
||
export default Docker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { folder } from 'leva'; | ||
import { cloneDeep, pick } from 'lodash-es'; | ||
|
||
import { shieldBaseControls } from '@/const/shieldBaseControls'; | ||
|
||
export const defaultControls = { | ||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | ||
packageName: 'lobehub/lobe-chat', | ||
/* eslint-enable */ | ||
}; | ||
|
||
export const defaultControlsExtra = { | ||
...defaultControls, | ||
['⚒️']: folder(pick(cloneDeep(shieldBaseControls), ['color', 'labelColor', 'style']), { | ||
collapsed: true, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import urlJoin from 'url-join'; | ||
|
||
import { colorOptions } from '@/const/shieldBaseControls'; | ||
import { DOCKER_URL, SHIELD_DOCKER_URL } from '@/const/url'; | ||
import { ShieldsBaseOptions } from '@/types/shields'; | ||
import { genPickList } from '@/utils/genPickList'; | ||
|
||
export interface DockerShieldControlItem extends Partial<ShieldsBaseOptions> { | ||
genLink?: (packageName: string) => string | undefined; | ||
suffix?: string; | ||
url: string; | ||
} | ||
|
||
const genLink: DockerShieldControlItem['genLink'] = (packageName) => | ||
urlJoin(DOCKER_URL, packageName); | ||
|
||
export const dockerShieldControls: { | ||
[key: string]: DockerShieldControlItem; | ||
} = { | ||
/* eslint-disable sort-keys-fix/sort-keys-fix */ | ||
release: { | ||
logo: 'docker', | ||
logoColor: 'white', | ||
color: colorOptions.geekblue, | ||
genLink, | ||
url: urlJoin(SHIELD_DOCKER_URL, 'v'), | ||
}, | ||
size: { | ||
genLink, | ||
color: colorOptions.geekblue, | ||
url: urlJoin(SHIELD_DOCKER_URL, 'image-size'), | ||
}, | ||
pulls: { | ||
genLink, | ||
color: colorOptions.green, | ||
url: urlJoin(SHIELD_DOCKER_URL, 'pulls'), | ||
}, | ||
/* eslint-enable */ | ||
}; | ||
|
||
export const dockerShieldControlsPickList = genPickList(dockerShieldControls); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1 @@ | ||
export { default as ReadmeContributing } from './ReadmeContributing'; | ||
export { default as ReadmeCredits } from './ReadmeCredits'; | ||
export { default as ReadmeDevelopment } from './ReadmeDevelopment'; | ||
export { default as ReadmeFeatures } from './ReadmeFeatures'; | ||
export { default as ReadmeHero } from './ReadmeHero'; | ||
export { default as ReadmeInstallation } from './ReadmeInstallation'; | ||
export { default as ReadmeLicense } from './ReadmeLicense'; | ||
export { default as ShieldsBilibili } from './ShieldsBilibili'; | ||
export * from './ShieldsCustom'; | ||
export { default as ShieldsDiscord } from './ShieldsDiscord'; | ||
export * from './ShieldsGithub'; | ||
export { default as ShieldsNpm } from './ShieldsNpm'; | ||
export * from './ShieldsVercel'; | ||
export { default as ShieldsWebsite } from './ShieldsWebsite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { identity, pickBy } from 'lodash-es'; | ||
import qs from 'query-string'; | ||
import urlJoin from 'url-join'; | ||
|
||
import { DockerShieldControlItem, dockerShieldControls } from '@/const/dockerShieldControls'; | ||
import { DockerShieldBaseOptions } from '@/types/shields'; | ||
import { genShield } from '@/utils/genShield'; | ||
|
||
interface DockerShieldOptions extends DockerShieldBaseOptions, DockerShieldControlItem { | ||
name: string; | ||
} | ||
|
||
export const genDockerShield = (options: DockerShieldOptions) => { | ||
const { packageName, url, suffix, name, genLink, ...config } = options; | ||
|
||
const formatUrl = [url, packageName, suffix].filter(Boolean) as string[]; | ||
const defShield = qs.stringifyUrl({ | ||
query: pickBy(config, identity) as any, | ||
url: urlJoin(...formatUrl), | ||
}); | ||
const defLink = genLink?.(packageName); | ||
|
||
return genShield(`docker-${name}`, defShield, defLink); | ||
}; | ||
|
||
export const genDockerShields = ( | ||
options: Partial<DockerShieldOptions> | any, | ||
pickOptions: { [key: string]: boolean }, | ||
) => { | ||
const defShields: string[] = []; | ||
const defLinks: string[] = []; | ||
|
||
for (const [name, config] of Object.entries(dockerShieldControls)) { | ||
if (!pickOptions[name]) continue; | ||
const data = genDockerShield({ name, ...options, ...config }); | ||
defShields.push(data[0]); | ||
defLinks.push(data[1]); | ||
} | ||
return [defShields.join('\n'), defLinks.join('\n')]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters