diff --git a/README.md b/README.md index c53ad609..6c660a35 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pages/api/stats.svg.ts b/pages/api/stats.svg.ts new file mode 100644 index 00000000..df95a89b --- /dev/null +++ b/pages/api/stats.svg.ts @@ -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