kopia lustrzana https://github.com/badgen/badgen.net
				
				
				
			Migrate runkit endpoint to v2
							rodzic
							
								
									e2414a7a38
								
							
						
					
					
						commit
						fa35ebc5b2
					
				| 
						 | 
				
			
			@ -0,0 +1,89 @@
 | 
			
		|||
import got from '../libs/got'
 | 
			
		||||
import {
 | 
			
		||||
  badgenServe,
 | 
			
		||||
  BadgenServeMeta as Meta,
 | 
			
		||||
  BadgenServeHandlers as Handlers,
 | 
			
		||||
  BadgenServeHandlerArgs as Args
 | 
			
		||||
} from '../libs/badgen-serve'
 | 
			
		||||
 | 
			
		||||
const help = `## URL
 | 
			
		||||
 | 
			
		||||
    /runkit/cal-badge-icd0onfvrxx6/Asia/Shanghai
 | 
			
		||||
            ──┬─────────────────── ──┬──────────
 | 
			
		||||
              └─ endpoint-id         └─ path-args (optional)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## RunKit Endpoint
 | 
			
		||||
 | 
			
		||||
https://runkit.com/home#endpoint
 | 
			
		||||
 | 
			
		||||
If you are not familiar with RunKit endpoint, [this guide](https://runkit.com/docs/endpoint) would help.
 | 
			
		||||
 | 
			
		||||
## Use Badgen with RunKit Endpoint
 | 
			
		||||
 | 
			
		||||
1. Create a RunKit notebook (e.g. https://runkit.com/amio/cal-badge), which gives you an endpoint:
 | 
			
		||||
 | 
			
		||||
    \`\`\`
 | 
			
		||||
    https://cal-badge-icd0onfvrxx6.runkit.sh
 | 
			
		||||
    \`\`\`
 | 
			
		||||
 | 
			
		||||
  it would response with a JSON like:
 | 
			
		||||
 | 
			
		||||
    \`\`\`
 | 
			
		||||
    {
 | 
			
		||||
      "subject": "2019",
 | 
			
		||||
      "status": "6-1",
 | 
			
		||||
      "color": "blue"
 | 
			
		||||
    }
 | 
			
		||||
    \`\`\`
 | 
			
		||||
 | 
			
		||||
2. Click <kbd>endpoint</kbd> on notebook page for the endpoint address, then you have \`endpoint-id\` from it's subdomain:
 | 
			
		||||
 | 
			
		||||
    \`\`\`
 | 
			
		||||
    cal-badge-icd0onfvrxx6
 | 
			
		||||
    \`\`\`
 | 
			
		||||
 | 
			
		||||
3. Use the \`endpoint-id\` for badgen url:
 | 
			
		||||
 | 
			
		||||
    \`\`\`
 | 
			
		||||
    https://badgen.net/runkit/cal-badge-icd0onfvrxx6
 | 
			
		||||
    \`\`\`
 | 
			
		||||
 | 
			
		||||
  That's it:
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
Further more, you can append arbitrary path args (e.g. \`/Asia/Shanghai\`) to the end of url, Badgen will request runkit endpoint with that. This badge:
 | 
			
		||||
 | 
			
		||||
\`\`\`
 | 
			
		||||
https://badgen.net/runkit/cal-badge-icd0onfvrxx6/Asia/Shanghai
 | 
			
		||||
\`\`\`
 | 
			
		||||
 | 
			
		||||
represents badge data from:
 | 
			
		||||
 | 
			
		||||
\`\`\`
 | 
			
		||||
https://cal-badge-icd0onfvrxx6.runkit.sh/Asia/Shanghai
 | 
			
		||||
\`\`\`
 | 
			
		||||
`
 | 
			
		||||
 | 
			
		||||
export const meta: Meta = {
 | 
			
		||||
  title: 'RunKit',
 | 
			
		||||
  examples: {
 | 
			
		||||
    '/runkit/satisfaction-flq08o9mm3ka/102909/topic': 'satisfaction (topic)',
 | 
			
		||||
    '/runkit/satisfaction-flq08o9mm3ka/102909/people': 'satisfaction (people)',
 | 
			
		||||
    '/runkit/satisfaction-flq08o9mm3ka/102909/employee': 'satisfaction (employ)',
 | 
			
		||||
  },
 | 
			
		||||
  help
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const handlers: Handlers = {
 | 
			
		||||
  '/runkit/:endpoint-id': handler,
 | 
			
		||||
  '/runkit/:endpoint-id/:path+': handler
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function handler ({ 'endpoint-id': id, path }: Args) {
 | 
			
		||||
  const endpoint = `https://${id}.runkit.sh/${path || ''}`
 | 
			
		||||
  return await got(endpoint).then(res => res.body)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default badgenServe(handlers)
 | 
			
		||||
| 
						 | 
				
			
			@ -42,6 +42,7 @@ export const liveBadgeList = [
 | 
			
		|||
  'opencollective',
 | 
			
		||||
  'keybase',
 | 
			
		||||
  'twitter',
 | 
			
		||||
  'runkit'
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
export async function loadBadgeMeta () {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ type BadgenHelpParams = {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
function genMarkdown ({ id, help, examples, routes }: BadgenHelpParams) {
 | 
			
		||||
  const Docs = help ? help : `# /${id}`
 | 
			
		||||
  const Docs = `# /${id}\n\n${help || ''}`
 | 
			
		||||
 | 
			
		||||
  const schemeLinks = routes.map(r => `- \`${r}\``)
 | 
			
		||||
  const Schemes = `## Schemes\n\n${schemeLinks.join('  \n')}`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue