badgen.net/components/help-info.tsx

158 wiersze
4.5 KiB
TypeScript
Czysty Zwykły widok Historia

/* eslint-disable @next/next/no-img-element */
2018-12-20 06:39:56 +00:00
import icons from 'badgen-icons'
2022-12-31 08:23:34 +00:00
import Image from 'next/image'
import BadgeList from '../public/.meta/badge-list.json'
2022-12-31 08:23:34 +00:00
2023-01-04 01:31:10 +00:00
// import { Open_Sans } from '@next/font/google'
// const openSans = Open_Sans({ subsets: ['latin'], weight: ['400'] })
2018-12-20 06:39:56 +00:00
2019-10-04 13:44:20 +00:00
export default function HomeIntro ({ isFlat = false }) {
2019-08-30 03:22:22 +00:00
return (
<div className={`help-info`}>
2019-08-24 08:24:46 +00:00
<pre>{explainCode(isFlat)}</pre>
2018-12-20 06:39:56 +00:00
2022-12-31 08:23:34 +00:00
<h3>Options</h3>
2018-12-20 06:39:56 +00:00
<ul>
<li>
<code>color</code>
2019-06-20 03:42:20 +00:00
Override default badge color.
2018-12-20 06:39:56 +00:00
<a href='/npm/dm/express?color=pink'>e.g.</a>
</li>
<li>
<code>icon</code>
2019-06-20 03:42:20 +00:00
Use builtin icon (or url for external icon) in front of subject text.
2018-12-20 06:39:56 +00:00
<a href='/badge/docker/v1.2.3/blue?icon=docker'>e.g.</a>
</li>
<li>
<code>list</code>
2019-06-14 02:19:42 +00:00
Set <code>list=|</code> will replace <code>,</code> with <code>|</code> in status text.
<a href='/badge/platform/ios,macos,tvos?list=|'>e.g.</a>
2018-12-20 06:39:56 +00:00
</li>
<li>
<code>label</code>
Override default subject text (<a href='https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding'>URL-Encoding</a> needed for spaces or special characters).
<a href='/badge/docker/v1.2.3/blue?label=container'>e.g.</a>
2018-12-20 06:39:56 +00:00
</li>
2019-07-06 10:12:35 +00:00
<li>
<code>labelColor</code>
Override default label color.
<a href='/npm/dm/express?labelColor=pink'>e.g.</a>
</li>
2019-10-04 12:45:52 +00:00
<li>
<code>scale</code>
Custom badge scale.
2019-10-04 12:45:52 +00:00
<a href='/badge/docker/v1.2.3/blue?icon=docker&scale=2'>e.g.</a>
</li>
<li>
<code>cache</code>
Live badge are cached in cdn for 24hrs (86400), you may limit it to a minimum of 5min (300).
<a href='/npm/dm/express?cache=600'>e.g.</a>
</li>
2018-12-20 06:39:56 +00:00
</ul>
<h3>Builtin Colors</h3>
{ colorExamples() }
<h3>Builtin Icons</h3>
{ iconExamples() }
<h3>Badge Generators</h3>
{
Object.keys(BadgeList).map(badge => {
const href = '/' + badge
return <a key={badge} href={href}><code>{href}</code></a>
})
}
2018-12-20 06:39:56 +00:00
<h3>Advanced usage</h3>
<ul>
<li>
<a href='/runkit'><code>/runkit</code></a>
2018-12-20 06:39:56 +00:00
create arbitrary live badge with RunKit's online IDE.
</li>
<li>
<a href='/https'><code>/https</code></a>
2019-07-06 15:17:32 +00:00
turn an api endpoint into a svg live badge.
2018-12-20 06:39:56 +00:00
</li>
</ul>
2022-12-31 10:37:29 +00:00
<style jsx>{`
2018-12-20 06:39:56 +00:00
pre {
font-size: 15px;
2022-12-31 08:23:34 +00:00
font-family: Menlo, Courier New, monospace;
font-weight: 300;
background-color: #EEF2F8;
padding: 20px;
2018-12-20 06:39:56 +00:00
}
code {
margin-right: 6px;
}
.help-info h3 {
2022-12-31 08:23:34 +00:00
font-family: Merriweather, serif;
margin: 2rem 0;
2022-12-31 10:37:29 +00:00
font-weight: 400;
2022-12-31 08:23:34 +00:00
}
2023-01-04 01:31:10 +00:00
ul { padding-left: 2em; font-family: "Open Sans", sans-serif }
2022-12-31 10:37:29 +00:00
li { vertical-align: top; font-size: 14px; line-height: 24px; color: #777; margin: 5px 0 }
code { padding: 0.3em 0.5em; display: pre; color: #333; background: #EEF2F8 }
a { display: inline; margin-right: 0.3em }
a:hover { text-decoration: underline }
2022-12-31 08:23:34 +00:00
a code { color: #06D }
2019-08-24 08:24:46 +00:00
`}
</style>
2018-12-20 06:39:56 +00:00
</div>
2019-08-30 03:22:22 +00:00
)}
2018-12-20 06:39:56 +00:00
const colorExamples = () => {
2019-06-12 02:40:06 +00:00
const colors = ['blue', 'cyan', 'green', 'yellow', 'orange', 'red', 'pink', 'purple', 'grey', 'black']
2018-12-20 06:39:56 +00:00
return colors.map(c => (
<a href={`/badge/color/${c}/${c}`} key={c}>
<img alt={c} src={`/static/color/${c}/${c}`} />
2022-12-31 08:23:34 +00:00
<style>{`
2018-12-20 06:39:56 +00:00
a {
margin-right: 4px;
}
2019-08-24 08:24:46 +00:00
`}
</style>
2018-12-20 06:39:56 +00:00
</a>
))
}
const iconExamples = () => {
return Object.keys(icons).map(icon => {
2019-06-12 11:14:13 +00:00
const url = `/badge/icon/${icon}?icon=${icon}&label`
2018-12-20 06:39:56 +00:00
return (
2019-05-17 12:25:09 +00:00
<a href={url} key={icon}>
<img alt={icon} src={url} />
2022-12-31 08:23:34 +00:00
<style>{`
2018-12-20 06:39:56 +00:00
a {
margin-right: 4px;
}
2019-08-24 08:24:46 +00:00
`}
</style>
2018-12-20 06:39:56 +00:00
</a>
)
})
}
2022-12-31 08:23:34 +00:00
const explainCode = (isFlat: Boolean) => {
2018-12-20 06:39:56 +00:00
const text = `
https://badgen.net/badge/:subject/:status/:color?icon=github
2019-07-01 07:39:51 +00:00
Options (label, list, icon, color)
2018-12-20 06:39:56 +00:00
TEXT TEXT RGB / COLOR_NAME ( optional )
"badge" - default (static) badge generator`
2022-12-31 08:23:34 +00:00
2018-12-20 06:39:56 +00:00
if (isFlat) {
return text
.replace('badgen.net', 'flat.badgen.net')
.replace(/\n/g, '\n ')
.trim()
}
2022-12-31 08:23:34 +00:00
return text.trim()
2018-12-20 06:39:56 +00:00
}