Skip to content

Commit

Permalink
πŸ“ Update readme stats badge
Browse files Browse the repository at this point in the history
  • Loading branch information
wei committed Nov 19, 2022
1 parent 4acae27 commit 80d94f2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Want your project to stand out? **Socialify** helps you showcase your project to

It includes a ton of options including custom logo, description, badges, and many fonts and background patterns to choose from.

Join [![thousands of repositories](https://socialify-usage-count-pclo66uxqtfh.runkit.sh/)](https://github.com/search?o=desc&q=%22socialify.git.ci%22&s=indexed&type=Code) today!
Join [![thousands of repositories](https://socialify.git.ci/api/stats.svg)](https://github.com/search?o=desc&q=%22socialify.git.ci%22&s=indexed&type=Code) today!

## Usage

Expand Down
45 changes: 45 additions & 0 deletions pages/api/stats.svg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { NextRequest } from 'next/server'
import { badgen } from 'badgen'
import statsEndpoint from './stats'

const statsSvgEndpoint = async (req: NextRequest) => {
let totalCount = 0

try {
const apiResponse = await (await statsEndpoint(req)).json()
if (apiResponse.total_count) {
totalCount = apiResponse.total_count
}
} catch (ex) {
console.error(ex)
}

const svg = totalCount
? badgen({
subject: '',
status: `${totalCount} repositories`,
color: 'black',
style: 'flat'
})
: badgen({
subject: '',
status: `thousands of repositories`,
color: 'black',
style: 'flat'
})

return new Response(svg, {
status: 200,
headers: {
'content-type': 'image/svg+xml',
'cache-control':
'public, immutable, no-transform, max-age=60, s-maxage=86400'
}
})
}

export const config = {
runtime: 'experimental-edge'
}

export default statsSvgEndpoint

0 comments on commit 80d94f2

Please # to comment.