Skip to content

Commit 5c2e77d

Browse files
πŸ› fix: Fix sponsor kit
1 parent 8b89973 commit 5c2e77d

File tree

10 files changed

+158
-1247
lines changed

10 files changed

+158
-1247
lines changed

β€Žapi/sponsor.tsx

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import { ImageResponse } from '@vercel/og';
2-
31
import cors from '../lib/cors';
4-
import Sponsor from '../src/Sponsor';
5-
import { caleHeight, fetchFonts, getNumber } from '../src/Sponsor/utils';
6-
import { fetchSponsors } from '../src/services/sponsorkit';
7-
8-
const MULTIPLE = 2;
2+
import { MULTIPLE, genSponsor } from '../lib/genSponsor';
3+
import { getNumber } from '../src/Sponsor/utils';
94

105
export const config = {
116
runtime: 'edge',
@@ -18,60 +13,8 @@ export default async function handler(request: Request): Promise<any> {
1813
const avatarSize = getNumber(searchParams.get('avatarSize'), 64 * MULTIPLE);
1914
const width = getNumber(searchParams.get('width'), 800 * MULTIPLE);
2015
const themeMode = searchParams.get('themeMode') === 'dark' ? 'dark' : 'light';
21-
const data = await fetchSponsors({
22-
github: {
23-
login: process.env.SPONSORKIT_GITHUB_LOGIN || '',
24-
token: process.env.SPONSORKIT_GITHUB_TOKEN || '',
25-
type: process.env.SPONSORKIT_GITHUB_TYPE || 'organization',
26-
},
27-
includePastSponsors: true,
28-
opencollective: {
29-
key: process.env.SPONSORKIT_OPENCOLLECTIVE_KEY || '',
30-
slug: process.env.SPONSORKIT_OPENCOLLECTIVE_ID || 'lobehub',
31-
type: process.env.SPONSORKIT_OPENCOLLECTIVE_TYPE || 'collective',
32-
},
33-
});
34-
35-
const { fontBold, fontRegular } = await fetchFonts();
36-
const height = caleHeight(data, { avatarSize, width } as any);
37-
38-
const res = new ImageResponse(
39-
(
40-
<Sponsor
41-
avatarSize={avatarSize}
42-
data={data}
43-
style={{ fontFamily: '"HarmonyOS Sans"' }}
44-
themeMode={themeMode}
45-
width={width}
46-
/>
47-
),
48-
{
49-
emoji: 'fluent',
50-
fonts: [
51-
{
52-
data: fontRegular,
53-
name: 'HarmonyOS Sans',
54-
style: 'normal',
55-
weight: 400,
56-
},
57-
{
58-
data: fontBold,
59-
name: 'HarmonyOS Sans',
60-
style: 'normal',
61-
weight: 600,
62-
},
63-
],
64-
headers: {
65-
'CDN-Cache-Control': 'public, s-maxage=120',
66-
'Vercel-CDN-Cache-Control': 'public, s-maxage=3600',
67-
'cache-control': 'public, max-age=120, s-maxage=120',
68-
'content-type': 'image/png',
69-
},
70-
height,
71-
width,
72-
},
73-
);
7416

17+
const res = await genSponsor({ avatarSize, themeMode, width });
7518
return cors(request, res);
7619
} catch (error: any) {
7720
console.log(`${error.message}`);

β€Žlib/genSponsor.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { ImageResponse } from '@vercel/og';
2+
3+
import Sponsor from '../src/Sponsor';
4+
import { caleHeight, fetchFonts } from '../src/Sponsor/utils';
5+
import { fetchSponsors } from '../src/services/sponsorkit';
6+
7+
export const MULTIPLE = 2;
8+
9+
export const genSponsor = async ({
10+
avatarSize = 64 * MULTIPLE,
11+
width = 800 * MULTIPLE,
12+
themeMode = 'dark',
13+
}: {
14+
avatarSize?: number;
15+
themeMode: 'dark' | 'light';
16+
width?: number;
17+
}): Promise<Response> => {
18+
const data = await fetchSponsors({
19+
github: {
20+
login: process.env.SPONSORKIT_GITHUB_LOGIN || '',
21+
token: process.env.SPONSORKIT_GITHUB_TOKEN || '',
22+
type: process.env.SPONSORKIT_GITHUB_TYPE || 'organization',
23+
},
24+
includePastSponsors: true,
25+
opencollective: {
26+
key: process.env.SPONSORKIT_OPENCOLLECTIVE_KEY || '',
27+
slug: process.env.SPONSORKIT_OPENCOLLECTIVE_ID || 'lobehub',
28+
type: process.env.SPONSORKIT_OPENCOLLECTIVE_TYPE || 'collective',
29+
},
30+
});
31+
32+
const { fontBold, fontRegular } = await fetchFonts();
33+
const height = caleHeight(data, { avatarSize, width } as any);
34+
35+
return new ImageResponse(
36+
(
37+
<Sponsor
38+
avatarSize={avatarSize}
39+
data={data}
40+
style={{ fontFamily: '"HarmonyOS Sans"' }}
41+
themeMode={themeMode}
42+
width={width}
43+
/>
44+
),
45+
{
46+
emoji: 'fluent',
47+
fonts: [
48+
{
49+
data: fontRegular,
50+
name: 'HarmonyOS Sans',
51+
style: 'normal',
52+
weight: 400,
53+
},
54+
{
55+
data: fontBold,
56+
name: 'HarmonyOS Sans',
57+
style: 'normal',
58+
weight: 600,
59+
},
60+
],
61+
headers: {
62+
'CDN-Cache-Control': 'public, s-maxage=120',
63+
'Vercel-CDN-Cache-Control': 'public, s-maxage=3600',
64+
'cache-control': 'public, max-age=120, s-maxage=120',
65+
'content-type': 'image/png',
66+
},
67+
height,
68+
width,
69+
},
70+
);
71+
};

β€Žpackage.json

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"build": "dumi build",
1818
"ci": "npm run lint",
1919
"dev": "dumi dev",
20+
"dev:api": "vercel dev -y",
2021
"i18n": "lobe-i18n",
2122
"icon-sync": "node ./scripts/syncSimpleIconList.mjs",
2223
"lint": "npm run lint:ts && npm run lint:style",
@@ -55,70 +56,76 @@
5556
]
5657
},
5758
"dependencies": {
58-
"@babel/runtime": "^7.26.0",
59-
"@vercel/og": "0.5.18",
60-
"dotenv": "^16.4.5",
59+
"@babel/runtime": "^7.26.7",
60+
"@lobehub/ui": "^1.164.11",
61+
"@vercel/og": "~0.6.5",
62+
"ahooks": "^3.8.4",
63+
"antd": "^5.23.4",
64+
"antd-style": "^3.7.1",
65+
"dotenv": "^16.4.7",
6166
"fast-deep-equal": "^3.1.3",
6267
"immer": "^10.1.1",
68+
"leva": "^0.10.0",
6369
"lodash-es": "^4.17.21",
70+
"lucide-react": "^0.396.0",
6471
"node-html-parser": "^6.1.13",
6572
"polished": "^4.3.1",
66-
"query-string": "^8.2.0",
67-
"react-markdown": "^8.0.7",
73+
"query-string": "^9.1.1",
74+
"react": "^19.0.0",
75+
"react-dom": "^19.0.0",
76+
"react-layout-kit": "^1.9.1",
77+
"react-markdown": "^9.0.3",
6878
"react-syntax-highlighter": "^15.6.1",
69-
"rehype-highlight": "^7.0.1",
79+
"rehype-highlight": "^7.0.2",
7080
"rehype-raw": "^7.0.0",
71-
"remark-gfm": "^3.0.1",
72-
"remark-slug": "^7.0.1",
73-
"remark-toc": "^8.0.1",
81+
"remark-gfm": "^4.0.0",
82+
"remark-toc": "^9.0.0",
7483
"simple-icons": "^10.4.0",
75-
"swr": "^2.2.5",
84+
"swr": "^2.3.2",
7685
"url-join": "^5.0.0",
7786
"use-merge-value": "^1.2.0",
7887
"utility-types": "^3.11.0",
79-
"zustand": "^4.5.5",
88+
"zustand": "^4.5.6",
8089
"zustand-utils": "^1.3.2"
8190
},
8291
"devDependencies": {
83-
"@commitlint/cli": "^18.6.1",
84-
"@lobehub/lint": "latest",
92+
"@commitlint/cli": "^19.7.1",
93+
"@lobehub/lint": "^1.25.7",
8594
"@testing-library/react": "^14.3.1",
8695
"@types/lodash-es": "^4.17.12",
87-
"@types/react": "^18.3.12",
88-
"@types/react-dom": "^18.3.1",
96+
"@types/react": "^19.0.8",
97+
"@types/react-dom": "^19.0.3",
8998
"@vitest/coverage-v8": "~1.2.2",
9099
"babel-plugin-antd-style": "^1.0.4",
91-
"commitlint": "^18.6.1",
92-
"concurrently": "^8.2.2",
100+
"commitlint": "^19.7.1",
101+
"concurrently": "^9.1.2",
93102
"cross-env": "^7.0.3",
94-
"dumi": "^2.4.14",
95-
"dumi-theme-lobehub": "^1.10.4",
103+
"dumi": "^2.4.17",
104+
"dumi-theme-lobehub": "^1.15.0",
96105
"eslint": "^8.57.1",
97-
"father": "^4.5.1",
106+
"father": "^4.5.2",
98107
"husky": "^9.1.7",
99-
"jsdom": "^23.2.0",
100-
"lint-staged": "^15.2.10",
101-
"prettier": "^3.3.3",
102-
"remark": "^14.0.3",
103-
"remark-cli": "^11.0.0",
108+
"jsdom": "^26.0.0",
109+
"lint-staged": "^15.4.3",
110+
"prettier": "^3.4.2",
111+
"remark": "^15.0.1",
112+
"remark-cli": "^12.0.1",
104113
"semantic-release": "^21.1.2",
105114
"stylelint": "^15.11.0",
106-
"typescript": "^5.7.2",
115+
"typescript": "^5.7.3",
116+
"vercel": "^39.2.6",
107117
"vitest": "~1.2.2"
108118
},
109-
"peerDependencies": {
110-
"@lobehub/ui": ">=1",
111-
"ahooks": ">=3",
112-
"antd": ">=5.13.0",
113-
"antd-style": ">=3",
114-
"leva": ">=0.9.35",
115-
"lucide-react": ">=0.396.0",
116-
"react": ">=18",
117-
"react-dom": ">=18",
118-
"react-layout-kit": ">=1"
119-
},
120119
"publishConfig": {
121120
"access": "public",
122121
"registry": "https://registry.npmjs.org"
122+
},
123+
"pnpm": {
124+
"overrides": {
125+
"mdast-util-gfm": "3.0.0"
126+
}
127+
},
128+
"overrides": {
129+
"mdast-util-gfm": "3.0.0"
123130
}
124131
}

0 commit comments

Comments
Β (0)