Skip to content

Commit

Permalink
πŸ› fix: Fix sponsor kit
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Feb 7, 2025
1 parent 8b89973 commit 5c2e77d
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 1,247 deletions.
63 changes: 3 additions & 60 deletions api/sponsor.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { ImageResponse } from '@vercel/og';

import cors from '../lib/cors';
import Sponsor from '../src/Sponsor';
import { caleHeight, fetchFonts, getNumber } from '../src/Sponsor/utils';
import { fetchSponsors } from '../src/services/sponsorkit';

const MULTIPLE = 2;
import { MULTIPLE, genSponsor } from '../lib/genSponsor';
import { getNumber } from '../src/Sponsor/utils';

export const config = {
runtime: 'edge',
Expand All @@ -18,60 +13,8 @@ export default async function handler(request: Request): Promise<any> {
const avatarSize = getNumber(searchParams.get('avatarSize'), 64 * MULTIPLE);
const width = getNumber(searchParams.get('width'), 800 * MULTIPLE);
const themeMode = searchParams.get('themeMode') === 'dark' ? 'dark' : 'light';
const data = await fetchSponsors({
github: {
login: process.env.SPONSORKIT_GITHUB_LOGIN || '',
token: process.env.SPONSORKIT_GITHUB_TOKEN || '',
type: process.env.SPONSORKIT_GITHUB_TYPE || 'organization',
},
includePastSponsors: true,
opencollective: {
key: process.env.SPONSORKIT_OPENCOLLECTIVE_KEY || '',
slug: process.env.SPONSORKIT_OPENCOLLECTIVE_ID || 'lobehub',
type: process.env.SPONSORKIT_OPENCOLLECTIVE_TYPE || 'collective',
},
});

const { fontBold, fontRegular } = await fetchFonts();
const height = caleHeight(data, { avatarSize, width } as any);

const res = new ImageResponse(
(
<Sponsor
avatarSize={avatarSize}
data={data}
style={{ fontFamily: '"HarmonyOS Sans"' }}
themeMode={themeMode}
width={width}
/>
),
{
emoji: 'fluent',
fonts: [
{
data: fontRegular,
name: 'HarmonyOS Sans',
style: 'normal',
weight: 400,
},
{
data: fontBold,
name: 'HarmonyOS Sans',
style: 'normal',
weight: 600,
},
],
headers: {
'CDN-Cache-Control': 'public, s-maxage=120',
'Vercel-CDN-Cache-Control': 'public, s-maxage=3600',
'cache-control': 'public, max-age=120, s-maxage=120',
'content-type': 'image/png',
},
height,
width,
},
);

const res = await genSponsor({ avatarSize, themeMode, width });
return cors(request, res);
} catch (error: any) {
console.log(`${error.message}`);
Expand Down
71 changes: 71 additions & 0 deletions lib/genSponsor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ImageResponse } from '@vercel/og';

import Sponsor from '../src/Sponsor';
import { caleHeight, fetchFonts } from '../src/Sponsor/utils';
import { fetchSponsors } from '../src/services/sponsorkit';

export const MULTIPLE = 2;

export const genSponsor = async ({
avatarSize = 64 * MULTIPLE,
width = 800 * MULTIPLE,
themeMode = 'dark',
}: {
avatarSize?: number;
themeMode: 'dark' | 'light';
width?: number;
}): Promise<Response> => {
const data = await fetchSponsors({
github: {
login: process.env.SPONSORKIT_GITHUB_LOGIN || '',
token: process.env.SPONSORKIT_GITHUB_TOKEN || '',
type: process.env.SPONSORKIT_GITHUB_TYPE || 'organization',
},
includePastSponsors: true,
opencollective: {
key: process.env.SPONSORKIT_OPENCOLLECTIVE_KEY || '',
slug: process.env.SPONSORKIT_OPENCOLLECTIVE_ID || 'lobehub',
type: process.env.SPONSORKIT_OPENCOLLECTIVE_TYPE || 'collective',
},
});

const { fontBold, fontRegular } = await fetchFonts();
const height = caleHeight(data, { avatarSize, width } as any);

return new ImageResponse(
(
<Sponsor
avatarSize={avatarSize}
data={data}
style={{ fontFamily: '"HarmonyOS Sans"' }}
themeMode={themeMode}
width={width}
/>
),
{
emoji: 'fluent',
fonts: [
{
data: fontRegular,
name: 'HarmonyOS Sans',
style: 'normal',
weight: 400,
},
{
data: fontBold,
name: 'HarmonyOS Sans',
style: 'normal',
weight: 600,
},
],
headers: {
'CDN-Cache-Control': 'public, s-maxage=120',
'Vercel-CDN-Cache-Control': 'public, s-maxage=3600',
'cache-control': 'public, max-age=120, s-maxage=120',
'content-type': 'image/png',
},
height,
width,
},
);
};
81 changes: 44 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": "dumi build",
"ci": "npm run lint",
"dev": "dumi dev",
"dev:api": "vercel dev -y",
"i18n": "lobe-i18n",
"icon-sync": "node ./scripts/syncSimpleIconList.mjs",
"lint": "npm run lint:ts && npm run lint:style",
Expand Down Expand Up @@ -55,70 +56,76 @@
]
},
"dependencies": {
"@babel/runtime": "^7.26.0",
"@vercel/og": "0.5.18",
"dotenv": "^16.4.5",
"@babel/runtime": "^7.26.7",
"@lobehub/ui": "^1.164.11",
"@vercel/og": "~0.6.5",
"ahooks": "^3.8.4",
"antd": "^5.23.4",
"antd-style": "^3.7.1",
"dotenv": "^16.4.7",
"fast-deep-equal": "^3.1.3",
"immer": "^10.1.1",
"leva": "^0.10.0",
"lodash-es": "^4.17.21",
"lucide-react": "^0.396.0",
"node-html-parser": "^6.1.13",
"polished": "^4.3.1",
"query-string": "^8.2.0",
"react-markdown": "^8.0.7",
"query-string": "^9.1.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-layout-kit": "^1.9.1",
"react-markdown": "^9.0.3",
"react-syntax-highlighter": "^15.6.1",
"rehype-highlight": "^7.0.1",
"rehype-highlight": "^7.0.2",
"rehype-raw": "^7.0.0",
"remark-gfm": "^3.0.1",
"remark-slug": "^7.0.1",
"remark-toc": "^8.0.1",
"remark-gfm": "^4.0.0",
"remark-toc": "^9.0.0",
"simple-icons": "^10.4.0",
"swr": "^2.2.5",
"swr": "^2.3.2",
"url-join": "^5.0.0",
"use-merge-value": "^1.2.0",
"utility-types": "^3.11.0",
"zustand": "^4.5.5",
"zustand": "^4.5.6",
"zustand-utils": "^1.3.2"
},
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@lobehub/lint": "latest",
"@commitlint/cli": "^19.7.1",
"@lobehub/lint": "^1.25.7",
"@testing-library/react": "^14.3.1",
"@types/lodash-es": "^4.17.12",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitest/coverage-v8": "~1.2.2",
"babel-plugin-antd-style": "^1.0.4",
"commitlint": "^18.6.1",
"concurrently": "^8.2.2",
"commitlint": "^19.7.1",
"concurrently": "^9.1.2",
"cross-env": "^7.0.3",
"dumi": "^2.4.14",
"dumi-theme-lobehub": "^1.10.4",
"dumi": "^2.4.17",
"dumi-theme-lobehub": "^1.15.0",
"eslint": "^8.57.1",
"father": "^4.5.1",
"father": "^4.5.2",
"husky": "^9.1.7",
"jsdom": "^23.2.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"remark": "^14.0.3",
"remark-cli": "^11.0.0",
"jsdom": "^26.0.0",
"lint-staged": "^15.4.3",
"prettier": "^3.4.2",
"remark": "^15.0.1",
"remark-cli": "^12.0.1",
"semantic-release": "^21.1.2",
"stylelint": "^15.11.0",
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"vercel": "^39.2.6",
"vitest": "~1.2.2"
},
"peerDependencies": {
"@lobehub/ui": ">=1",
"ahooks": ">=3",
"antd": ">=5.13.0",
"antd-style": ">=3",
"leva": ">=0.9.35",
"lucide-react": ">=0.396.0",
"react": ">=18",
"react-dom": ">=18",
"react-layout-kit": ">=1"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"pnpm": {
"overrides": {
"mdast-util-gfm": "3.0.0"
}
},
"overrides": {
"mdast-util-gfm": "3.0.0"
}
}
Loading

0 comments on commit 5c2e77d

Please sign in to comment.