Skip to content

Commit

Permalink
πŸ“ Update readme stats badge (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
wei committed Nov 19, 2022
1 parent 1a50593 commit a964da5
Show file tree
Hide file tree
Showing 4 changed files with 52 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@vercel/analytics": "^0.1.5",
"@vercel/og": "^0.0.20",
"antd": "^4.24.1",
"badgen": "^3.2.2",
"copee": "^1.0.6",
"cross-fetch": "^3.1.5",
"hero-patterns": "^2.1.0",
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
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,11 @@ babel-preset-react-app@^10.0.1:
babel-plugin-macros "^3.1.0"
babel-plugin-transform-react-remove-prop-types "^0.4.24"

badgen@^3.2.2:
version "3.2.2"
resolved "https://registry.npmjs.org/badgen/-/badgen-3.2.2.tgz#7556b520055c4952ee46229c57d7a1cc71a85748"
integrity sha512-MfBNhOzp+qbTg/3BAeaK1g+VE3uZ0CRfqMyrfyI3JUBz7b+DwxrZbYQdz5JQnibRih9YOVzXuVJl3A3xaWXfFQ==

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down

0 comments on commit a964da5

Please sign in to comment.