From 80d94f228d1ef4258d73ea028592edfe0455bb59 Mon Sep 17 00:00:00 2001 From: Wei He Date: Sat, 19 Nov 2022 17:06:46 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Update=20readme=20stats=20badge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pages/api/stats.svg.ts | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 pages/api/stats.svg.ts 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