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/package.json b/package.json index 48478dcd..96ed394e 100644 --- a/package.json +++ b/package.json @@ -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", 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 diff --git a/yarn.lock b/yarn.lock index 014fea44..572f8d5f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"