diff --git a/api/sponsor.tsx b/api/sponsor.tsx index 04e357e..d310620 100644 --- a/api/sponsor.tsx +++ b/api/sponsor.tsx @@ -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', @@ -18,60 +13,8 @@ export default async function handler(request: Request): Promise { 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( - ( - - ), - { - 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}`); diff --git a/lib/genSponsor.tsx b/lib/genSponsor.tsx new file mode 100644 index 0000000..f7a2ae8 --- /dev/null +++ b/lib/genSponsor.tsx @@ -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 => { + 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( + ( + + ), + { + 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, + }, + ); +}; diff --git a/package.json b/package.json index 8af9d80..8749e55 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/Sponsor/demos/data.ts b/src/Sponsor/demos/data.ts deleted file mode 100644 index 8bad84c..0000000 --- a/src/Sponsor/demos/data.ts +++ /dev/null @@ -1,1058 +0,0 @@ -import { Sponsorship } from '@/services/sponsorkit/types'; - -const data: Sponsorship[] = [ - { - createdAt: '2024-04-28T17:54:03Z', - isOneTime: true, - monthlyDollars: 20, - privacyLevel: 'PUBLIC', - sponsor: { - avatarUrl: - 'https://avatars.githubusercontent.com/u/659203?u=ece91cb3b5c3b4a1c78637ab20753c2143b3d963&v=4', - linkUrl: 'https://github.com/wilbeibi', - login: 'wilbeibi', - name: 'Hongyi Shen', - type: 'User', - websiteUrl: 'https://wilbeibi.com', - }, - tierName: '$20 one time', - }, - { - isOneTime: false, - monthlyDollars: 6, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 6 }, - createdAt: '2024-03-10T05:36:41.232Z', - frequency: 'MONTHLY', - fromAccount: { - id: 'gnxdwzj3-le5mpwjy-ojeqy8rv-bko04a97', - imageUrl: 'https://images.opencollective.com/sdiggly-7462/avatar/460.png', - isIncognito: false, - name: 'sdiggly#7462', - slug: 'sdiggly-7462', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '3k0exgzn-m8yj64gd-j9765wao-9r7b4dlv', - status: 'ACTIVE', - tier: { name: '☕ Backer' }, - totalDonations: { value: 12 }, - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/sdiggly-7462/avatar/460.png', - linkUrl: 'https://opencollective.com/sdiggly-7462', - login: 'sdiggly-7462', - name: 'sdiggly#7462', - type: 'User', - }, - tierName: '☕ Backer', - }, - { - isOneTime: false, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 6 }, - createdAt: '2024-02-28T21:23:35.853Z', - frequency: 'MONTHLY', - fromAccount: { - id: '3z8arxve-ymko60va-ly8qgl5n-bj9w704d', - imageUrl: 'https://images.opencollective.com/ray-thurman/avatar/460.png', - isIncognito: false, - name: 'Ray Thurman', - slug: 'ray-thurman', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'n4gx0bro-v5m96nkd-9aj6d8lk-3ey7jzwa', - status: 'CANCELLED', - tier: { name: '☕ Backer' }, - totalDonations: { value: 6 }, - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/ray-thurman/avatar/460.png', - linkUrl: 'https://opencollective.com/ray-thurman', - login: 'ray-thurman', - name: 'Ray Thurman', - type: 'User', - }, - tierName: '☕ Backer', - }, - { - isOneTime: false, - monthlyDollars: 0.416_666_666_666_666_7, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 5 }, - createdAt: '2024-01-30T07:48:02.300Z', - frequency: 'YEARLY', - fromAccount: { - id: 'rxg0j35l-zkwm6vvn-lmb6voe9-8n47daby', - imageUrl: 'https://images.opencollective.com/guang3-an1/avatar/460.png', - isIncognito: false, - name: '广安', - slug: 'guang3-an1', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'v349mrwg-z75lpy5a-4br6a08d-jeybknox', - status: 'ACTIVE', - tier: null, - totalDonations: { value: 5 }, - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/guang3-an1/avatar/460.png', - linkUrl: 'https://opencollective.com/guang3-an1', - login: 'guang3-an1', - name: '广安', - type: 'User', - }, - }, - { - isOneTime: false, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 100 }, - createdAt: '2023-12-24T10:00:00.853Z', - frequency: 'MONTHLY', - fromAccount: { - id: 'k3z8arxv-eymko60l-j4w6gl5n-bj9w704d', - imageUrl: 'https://images.opencollective.com/zhukunpeng/d095342/avatar/460.png', - isIncognito: false, - name: '朱昆鹏', - slug: 'zhukunpeng', - socialLinks: [ - { type: 'WEBSITE', url: 'https://zhukunpeng.com/' }, - { type: 'GITHUB', url: 'https://github.com/zhukunpenglinyutong' }, - ], - type: 'INDIVIDUAL', - }, - id: '8k03reyd-5agmq505-bbkplbwo-z7j4nxv9', - status: 'CANCELLED', - tier: { name: '🥈 Silver Sponsor' }, - totalDonations: { value: 155 }, - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/zhukunpeng/d095342/avatar/460.png', - linkUrl: 'https://opencollective.com/zhukunpeng', - login: 'zhukunpeng', - name: '朱昆鹏', - type: 'User', - websiteUrl: 'https://zhukunpeng.com/', - }, - tierName: '🥈 Silver Sponsor', - }, - { - isOneTime: false, - monthlyDollars: 100, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 100 }, - createdAt: '2023-12-04T05:11:12.552Z', - frequency: 'MONTHLY', - fromAccount: { - id: 'mvrwng4k-j03dpb9j-m4z6z57o-yl9e8xba', - imageUrl: 'https://images.opencollective.com/lucas40/avatar/460.png', - isIncognito: false, - name: 'Lucas', - slug: 'lucas40', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'mvrwng4k-j03dpb93-awz6z57o-yl9e8xba', - status: 'ACTIVE', - tier: { name: '🥈 Silver Sponsor' }, - totalDonations: { value: 500 }, - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/lucas40/avatar/460.png', - linkUrl: 'https://opencollective.com/lucas40', - login: 'lucas40', - name: 'Lucas', - type: 'User', - }, - tierName: '🥈 Silver Sponsor', - }, - { - createdAt: '2024-04-25T07:26:14.630Z', - isOneTime: true, - monthlyDollars: 1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2024-04-25T07:26:14.630Z', - fromAccount: { - id: 'vrgbk357-l4x96e7k-awkpomew-a0jdyzn8', - imageUrl: 'https://images.opencollective.com/dale5/4463617/avatar/460.png', - isIncognito: false, - name: 'Feng', - slug: 'dale5', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'c039f76b-4dc9-40cb-abbb-24cf9c89a803', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: 'jrkx5lmn-v904qjly-8zz68bwa-7zdygoe3', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/dale5/4463617/avatar/460.png', - linkUrl: 'https://opencollective.com/dale5', - login: 'dale5', - name: 'Feng', - type: 'User', - }, - }, - { - createdAt: '2024-04-18T14:33:17.490Z', - isOneTime: true, - monthlyDollars: 1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2024-04-18T14:33:17.490Z', - fromAccount: { - id: '3k0exgzn-m8yj64g7-j4j65wao-9r7b4dlv', - imageUrl: 'https://images.opencollective.com/guest-53e23266/avatar/460.png', - isIncognito: false, - name: 'Guest', - slug: 'guest-53e23266', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '3abc0add-f5dc-4620-976c-2d08233de43d', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: 'vedj9wro-z3a56dga-lrl67blg-8x4m0ykn', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/guest-53e23266/avatar/460.png', - linkUrl: 'https://opencollective.com/guest-53e23266', - login: 'guest-53e23266', - name: 'Guest', - type: 'User', - }, - }, - { - createdAt: '2024-04-01T03:20:47.363Z', - isOneTime: true, - monthlyDollars: 52, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 52 }, - createdAt: '2024-04-01T03:20:47.363Z', - fromAccount: { - id: '3kzxy4v0-7wlr6mk5-en7qmj9n-o8agdbe5', - imageUrl: 'https://images.opencollective.com/reed/4f34443/avatar/460.png', - isIncognito: false, - name: 'Reed', - slug: 'reed', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '56116e93-db52-4803-89c5-b3fc1b62b586', - kind: 'CONTRIBUTION', - order: { - amount: { value: 52 }, - frequency: 'ONETIME', - id: 'a47byg9n-xozdp8xg-7776mjlv-03rek5w8', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/reed/4f34443/avatar/460.png', - linkUrl: 'https://opencollective.com/reed', - login: 'reed', - name: 'Reed', - type: 'User', - }, - }, - { - createdAt: '2024-03-30T16:45:54.862Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 2 }, - createdAt: '2024-03-30T16:45:54.862Z', - fromAccount: { - id: 'e0adkjrv-8xwm69oj-mx467z5n-4l93bgoy', - imageUrl: 'https://images.opencollective.com/liaokong/be80283/avatar/460.png', - isIncognito: false, - name: 'LiaoKong', - slug: 'liaokong', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '3b07e6b6-b4c2-4bb5-88c1-845fb4607b4b', - kind: 'CONTRIBUTION', - order: { - amount: { value: 2 }, - frequency: 'ONETIME', - id: 'v349mrwg-z75lpy5n-w8z6a08d-jeybknox', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/liaokong/be80283/avatar/460.png', - linkUrl: 'https://opencollective.com/liaokong', - login: 'liaokong', - name: 'LiaoKong', - type: 'User', - }, - }, - { - createdAt: '2024-03-30T10:05:03.806Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2024-03-30T10:05:03.806Z', - fromAccount: { - id: 'ywz9j4av-god8pgwg-k0e6mr35-nxklb0e7', - imageUrl: 'https://images.opencollective.com/guest-324ee71e/avatar/460.png', - isIncognito: false, - name: 'Guest', - slug: 'guest-324ee71e', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '0439e524-3e09-4c62-bcde-b670854de782', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: 'gm9bnk80-437xqrn8-dgm6vzeo-ljdayw5r', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/guest-324ee71e/avatar/460.png', - linkUrl: 'https://opencollective.com/guest-324ee71e', - login: 'guest-324ee71e', - name: 'Guest', - type: 'User', - }, - }, - { - createdAt: '2024-03-30T03:09:32.570Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2024-03-30T03:09:32.570Z', - fromAccount: { - id: 'v349mrwg-z75lpy5v-0bz6a08d-jeybknox', - imageUrl: 'https://images.opencollective.com/user-377caa4e/avatar/460.png', - isIncognito: false, - name: 'Incognito', - slug: 'user-377caa4e', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '36b928e3-4fcf-447b-9974-b0184e55e94a', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: 'zaxon793-jy8gpl08-v7rpbrkd-emwl5v04', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/user-377caa4e/avatar/460.png', - linkUrl: 'https://opencollective.com/user-377caa4e', - login: 'user-377caa4e', - name: 'Incognito', - type: 'User', - }, - }, - { - createdAt: '2024-03-28T03:03:50.569Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 100 }, - createdAt: '2024-03-28T03:03:50.569Z', - fromAccount: { - id: 'ejoxl3az-45w9pa5m-w5e6y870-mgkbrvdn', - imageUrl: 'https://images.opencollective.com/user-55a29379/f051e78/avatar/460.png', - isIncognito: false, - name: 'mushan0x0', - slug: 'user-55a29379', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'db9845c1-5a97-4ec4-a3ef-91f51f3f627f', - kind: 'CONTRIBUTION', - order: { - amount: { value: 100 }, - frequency: 'ONETIME', - id: '3k0exgzn-m8yj64gn-nn965wao-9r7b4dlv', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/user-55a29379/f051e78/avatar/460.png', - linkUrl: 'https://opencollective.com/user-55a29379', - login: 'user-55a29379', - name: 'mushan0x0', - type: 'User', - }, - }, - { - createdAt: '2024-03-26T02:40:35.194Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 50 }, - createdAt: '2024-03-26T02:40:35.194Z', - fromAccount: { - id: 'zaxon793-jy8gpl0m-8jdpbrkd-emwl5v04', - imageUrl: 'https://images.opencollective.com/windwild/3194344/avatar/460.png', - isIncognito: false, - name: 'windwild', - slug: 'windwild', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '11507f76-0f65-497d-9282-7e92a6bd2128', - kind: 'CONTRIBUTION', - order: { - amount: { value: 50 }, - frequency: 'ONETIME', - id: 'n4gx0bro-v5m96nkv-do86d8lk-3ey7jzwa', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/windwild/3194344/avatar/460.png', - linkUrl: 'https://opencollective.com/windwild', - login: 'windwild', - name: 'windwild', - type: 'User', - }, - }, - { - createdAt: '2024-03-23T04:51:20.435Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 10 }, - createdAt: '2024-03-23T04:51:20.435Z', - fromAccount: { - id: 'v349mrwg-z75lpy5v-3vg6a08d-jeybknox', - imageUrl: 'https://images.opencollective.com/guest-63109dcc/avatar/460.png', - isIncognito: false, - name: 'RootFTW', - slug: 'guest-63109dcc', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '3e986197-f2a3-4241-b043-2f3f0f25d192', - kind: 'CONTRIBUTION', - order: { - amount: { value: 10 }, - frequency: 'ONETIME', - id: 'v349mrwg-z75lpy5n-aj56a08d-jeybknox', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/guest-63109dcc/avatar/460.png', - linkUrl: 'https://opencollective.com/guest-63109dcc', - login: 'guest-63109dcc', - name: 'RootFTW', - type: 'User', - }, - }, - { - createdAt: '2024-03-22T10:46:23.842Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 10 }, - createdAt: '2024-03-22T10:46:23.842Z', - fromAccount: { - id: 'vrgbk357-l4x96e79-g5apomew-a0jdyzn8', - imageUrl: 'https://images.opencollective.com/amelie3/0076fc5/avatar/460.png', - isIncognito: false, - name: 'Amelie', - slug: 'amelie3', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'd0b2c56c-1cb1-4610-ad75-803442f97d2c', - kind: 'CONTRIBUTION', - order: { - amount: { value: 10 }, - frequency: 'ONETIME', - id: 'mlo94zn7-x08dpo0z-34epewga-3vjbrky5', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/amelie3/0076fc5/avatar/460.png', - linkUrl: 'https://opencollective.com/amelie3', - login: 'amelie3', - name: 'Amelie', - type: 'User', - }, - }, - { - createdAt: '2024-03-05T13:57:16.026Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 10 }, - createdAt: '2024-03-05T13:57:16.026Z', - fromAccount: { - id: 'e0adkjrv-8xwm69ok-j8k67z5n-4l93bgoy', - imageUrl: 'https://images.opencollective.com/jinzd/avatar/460.png', - isIncognito: false, - name: 'Jinzd', - slug: 'jinzd', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '07fe1196-dda3-474f-9ca2-c44a25b7f349', - kind: 'CONTRIBUTION', - order: { - amount: { value: 10 }, - frequency: 'ONETIME', - id: 'vrgbk357-l4x96e7z-jykpomew-a0jdyzn8', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/jinzd/avatar/460.png', - linkUrl: 'https://opencollective.com/jinzd', - login: 'jinzd', - name: 'Jinzd', - type: 'User', - }, - }, - { - createdAt: '2024-03-04T15:49:45.009Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2024-03-04T15:49:45.009Z', - fromAccount: { - id: 'rxg0j35l-zkwm6vvw-lny6voe9-8n47daby', - imageUrl: 'https://images.opencollective.com/weber1/avatar/460.png', - isIncognito: false, - name: 'Weber', - slug: 'weber1', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '82972921-c57a-4205-a94f-9490246e17eb', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: '8rzownxl-9e50pxr7-zgbpymvb-dgk7j43a', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/weber1/avatar/460.png', - linkUrl: 'https://opencollective.com/weber1', - login: 'weber1', - name: 'Weber', - type: 'User', - }, - }, - { - createdAt: '2024-02-23T14:12:40.649Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 10 }, - createdAt: '2024-02-23T14:12:40.649Z', - fromAccount: { - id: 'jrkx5lmn-v904qjlg-kon68bwa-7zdygoe3', - imageUrl: 'https://images.opencollective.com/bugwz/040b242/avatar/460.png', - isIncognito: false, - name: 'bugwz', - slug: 'bugwz', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '9521e082-ddb9-433b-b520-134fa5e629ff', - kind: 'CONTRIBUTION', - order: { - amount: { value: 10 }, - frequency: 'ONETIME', - id: '3kzxy4v0-7wlr6mkr-48mqmj9n-o8agdbe5', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/bugwz/040b242/avatar/460.png', - linkUrl: 'https://opencollective.com/bugwz', - login: 'bugwz', - name: 'bugwz', - type: 'User', - }, - }, - { - createdAt: '2024-02-20T03:38:57.438Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 10 }, - createdAt: '2024-02-20T03:38:57.438Z', - fromAccount: { - id: 'vrgbk357-l4x96e7v-xgzpomew-a0jdyzn8', - imageUrl: 'https://images.opencollective.com/guest-11570536/avatar/460.png', - isIncognito: false, - name: 'Guest', - slug: 'guest-11570536', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'f46ae2f9-8e35-4fe5-bce4-157dbb1dabe7', - kind: 'CONTRIBUTION', - order: { - amount: { value: 10 }, - frequency: 'ONETIME', - id: 'k9mbw7y4-8r3zq3o0-jonq0ej5-lavnodgx', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/guest-11570536/avatar/460.png', - linkUrl: 'https://opencollective.com/guest-11570536', - login: 'guest-11570536', - name: 'Guest', - type: 'User', - }, - }, - { - createdAt: '2024-01-13T12:50:04.963Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 4 }, - createdAt: '2024-01-13T12:50:04.963Z', - fromAccount: { - id: 'ejoxl3az-45w9pa5m-kre6y870-mgkbrvdn', - imageUrl: 'https://images.opencollective.com/nagaame/5209ce5/avatar/460.png', - isIncognito: false, - name: '壳壳', - slug: 'nagaame', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '711c58f1-ed87-494f-a05b-ed3ff417e9f8', - kind: 'CONTRIBUTION', - order: { - amount: { value: 4 }, - frequency: 'ONETIME', - id: 'mywxoz34-09rl6k3b-58lqvenb-dj7gk85a', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/nagaame/5209ce5/avatar/460.png', - linkUrl: 'https://opencollective.com/nagaame', - login: 'nagaame', - name: '壳壳', - type: 'User', - }, - }, - { - createdAt: '2023-12-31T07:07:14.821Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 100 }, - createdAt: '2023-12-31T07:07:14.821Z', - fromAccount: { - id: 'e0adkjrv-8xwm69oy-z5k67z5n-4l93bgoy', - imageUrl: 'https://images.opencollective.com/xueliang-chen/31ea47b/avatar/460.png', - isIncognito: false, - name: 'Xueliang Chen', - slug: 'xueliang-chen', - socialLinks: [ - { type: 'GITHUB', url: 'https://github.com/Neko3000' }, - { type: 'TWITTER', url: 'https://twitter.com/sneko4000' }, - ], - type: 'INDIVIDUAL', - }, - id: 'c44774c0-5d39-4aae-8664-6df3a915aa7d', - kind: 'CONTRIBUTION', - order: { - amount: { value: 100 }, - frequency: 'ONETIME', - id: 'gm9bnk80-437xqrnj-vne6vzeo-ljdayw5r', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/xueliang-chen/31ea47b/avatar/460.png', - linkUrl: 'https://opencollective.com/xueliang-chen', - login: 'xueliang-chen', - name: 'Xueliang Chen', - type: 'User', - websiteUrl: 'https://github.com/Neko3000', - }, - }, - { - createdAt: '2023-12-30T01:13:06.573Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2023-12-30T01:13:06.573Z', - fromAccount: { - id: 'rxg0j35l-zkwm6vva-glm6voe9-8n47daby', - imageUrl: 'https://images.opencollective.com/hash070/dacd7d7/avatar/460.png', - isIncognito: false, - name: 'hash070', - slug: 'hash070', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '4191af7e-9a6e-4434-b775-8f1526fd9799', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: 'zaxon793-jy8gpl0x-m0dpbrkd-emwl5v04', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/hash070/dacd7d7/avatar/460.png', - linkUrl: 'https://opencollective.com/hash070', - login: 'hash070', - name: 'hash070', - type: 'User', - }, - }, - { - createdAt: '2023-12-26T17:36:38.105Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2023-12-26T17:36:38.105Z', - fromAccount: { - id: 'mvrwng4k-j03dpb9j-wm06z57o-yl9e8xba', - imageUrl: 'https://images.opencollective.com/sen/50bc263/avatar/460.png', - isIncognito: false, - name: 'Sen', - slug: 'sen', - socialLinks: [{ type: 'GITHUB', url: 'https://github.com/Sen-CaPoo' }], - type: 'INDIVIDUAL', - }, - id: 'bd8c9a88-dc00-4248-a8ac-2f8b6d2a7996', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: 'ejoxl3az-45w9pa59-xx46y870-mgkbrvdn', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/sen/50bc263/avatar/460.png', - linkUrl: 'https://opencollective.com/sen', - login: 'sen', - name: 'Sen', - type: 'User', - websiteUrl: 'https://github.com/Sen-CaPoo', - }, - }, - { - createdAt: '2023-12-24T09:46:58.719Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 11 }, - createdAt: '2023-12-24T09:46:58.719Z', - fromAccount: { - id: 'ywz9j4av-god8pgwo-ee96mr35-nxklb0e7', - imageUrl: 'https://images.opencollective.com/suwubee/e2a2dca/avatar/460.png', - isIncognito: false, - name: 'suwubee', - slug: 'suwubee', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '57c1ca04-85bc-4d89-8d3a-9dca3fc66297', - kind: 'CONTRIBUTION', - order: { - amount: { value: 11 }, - frequency: 'ONETIME', - id: 'vedj9wro-z3a56dgm-vva67blg-8x4m0ykn', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/suwubee/e2a2dca/avatar/460.png', - linkUrl: 'https://opencollective.com/suwubee', - login: 'suwubee', - name: 'suwubee', - type: 'User', - }, - }, - { - createdAt: '2023-12-23T11:25:55.738Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 5 }, - createdAt: '2023-12-23T11:25:55.738Z', - fromAccount: { - id: 'k3z8arxv-eymko60l-j4w6gl5n-bj9w704d', - imageUrl: 'https://images.opencollective.com/zhukunpeng/d095342/avatar/460.png', - isIncognito: false, - name: '朱昆鹏', - slug: 'zhukunpeng', - socialLinks: [ - { type: 'WEBSITE', url: 'https://zhukunpeng.com/' }, - { type: 'GITHUB', url: 'https://github.com/zhukunpenglinyutong' }, - ], - type: 'INDIVIDUAL', - }, - id: '57d18291-b109-40f9-a3a7-b406df4d61e5', - kind: 'CONTRIBUTION', - order: { - amount: { value: 5 }, - frequency: 'ONETIME', - id: 'gm9bnk80-437xqrnj-j9e6vzeo-ljdayw5r', - status: 'PAID', - tier: null, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/zhukunpeng/d095342/avatar/460.png', - linkUrl: 'https://opencollective.com/zhukunpeng', - login: 'zhukunpeng', - name: '朱昆鹏', - type: 'User', - websiteUrl: 'https://zhukunpeng.com/', - }, - }, - { - createdAt: '2023-12-16T08:16:09.191Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 10 }, - createdAt: '2023-12-16T08:16:09.191Z', - fromAccount: { - id: 'gnxdwzj3-le5mpwz0-4nepy8rv-bko04a97', - imageUrl: 'https://images.opencollective.com/lubeiluchen/a8c3717/avatar/460.png', - isIncognito: false, - name: '路北路陈', - slug: 'lubeiluchen', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '5116c8d1-30c3-4862-8040-55077a0907a0', - kind: 'CONTRIBUTION', - order: { - amount: { value: 10 }, - frequency: 'ONETIME', - id: 'mywxoz34-09rl6k3b-gbwqvenb-dj7gk85a', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/lubeiluchen/a8c3717/avatar/460.png', - linkUrl: 'https://opencollective.com/lubeiluchen', - login: 'lubeiluchen', - name: '路北路陈', - type: 'User', - }, - }, - { - createdAt: '2023-12-15T07:32:11.676Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 50 }, - createdAt: '2023-12-15T07:32:11.676Z', - fromAccount: { - id: 'rxg0j35l-zkwm6vva-x4m6voe9-8n47daby', - imageUrl: 'https://images.opencollective.com/moonlit/de693ad/avatar/460.png', - isIncognito: false, - name: 'Moonlit', - slug: 'moonlit', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: 'b1e019e2-f0ce-4a56-89ec-d054bfafdaa4', - kind: 'CONTRIBUTION', - order: { - amount: { value: 50 }, - frequency: 'ONETIME', - id: 'mywxoz34-09rl6k3b-wylqvenb-dj7gk85a', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/moonlit/de693ad/avatar/460.png', - linkUrl: 'https://opencollective.com/moonlit', - login: 'moonlit', - name: 'Moonlit', - type: 'User', - }, - }, - { - createdAt: '2023-12-12T11:16:19.808Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 1 }, - createdAt: '2023-12-12T11:16:19.808Z', - fromAccount: { - id: '5ax8emk7-lnw54q73-3my6gyvj-0o93zdrb', - imageUrl: 'https://images.opencollective.com/jtsang/a848378/avatar/460.png', - isIncognito: false, - name: 'JamesTsang', - slug: 'jtsang', - socialLinks: [ - { type: 'WEBSITE', url: 'https://jtsang.me/' }, - { type: 'GITHUB', url: 'http://github.com/jtsang4' }, - { type: 'TWITTER', url: 'https://twitter.com/JamesTsang19' }, - ], - type: 'INDIVIDUAL', - }, - id: 'efb26a80-b6d0-4437-bdd4-7401eaf0aaa4', - kind: 'CONTRIBUTION', - order: { - amount: { value: 1 }, - frequency: 'ONETIME', - id: 'gnxdwzj3-le5mpwz5-rjvpy8rv-bko04a97', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/jtsang/a848378/avatar/460.png', - linkUrl: 'https://opencollective.com/jtsang', - login: 'jtsang', - name: 'JamesTsang', - type: 'User', - websiteUrl: 'https://jtsang.me/', - }, - }, - { - createdAt: '2023-12-11T05:38:09.943Z', - isOneTime: true, - monthlyDollars: -1, - privacyLevel: 'PUBLIC', - raw: { - amount: { value: 10 }, - createdAt: '2023-12-11T05:38:09.943Z', - fromAccount: { - id: 'eng0kzdy-vor4pz8g-wkrpbma8-37xlw95j', - imageUrl: 'https://images.opencollective.com/limfoo/avatar/460.png', - isIncognito: false, - name: 'limfoo', - slug: 'limfoo', - socialLinks: [], - type: 'INDIVIDUAL', - }, - id: '7f055162-8188-4bb1-812a-8247c6ea75ee', - kind: 'CONTRIBUTION', - order: { - amount: { value: 10 }, - frequency: 'ONETIME', - id: 'zaxon793-jy8gpl0l-aknpbrkd-emwl5v04', - status: 'PAID', - tier: { name: '🌟 One Time' }, - }, - type: 'CREDIT', - }, - sponsor: { - avatarUrl: 'https://images.opencollective.com/limfoo/avatar/460.png', - linkUrl: 'https://opencollective.com/limfoo', - login: 'limfoo', - name: 'limfoo', - type: 'User', - }, - }, -]; - -export default data; diff --git a/src/Sponsor/demos/index.tsx b/src/Sponsor/demos/index.tsx index 27f204b..609ab98 100644 --- a/src/Sponsor/demos/index.tsx +++ b/src/Sponsor/demos/index.tsx @@ -1,12 +1,30 @@ import { Sponsor } from '@lobehub/readme-wizard'; import { StoryBook, useControls, useCreateStore } from '@lobehub/ui'; +import { Skeleton } from 'antd'; import { useThemeMode } from 'antd-style'; +import useSWR from 'swr'; + +import { fetchSponsors } from '@/services/sponsorkit'; import { DEFAULT_AVATAR_SIZE, DEFAULT_WIDTH } from '../const'; import { caleHeight } from '../utils'; -import data from './data'; export default () => { + const { data, isLoading } = useSWR('sponsor', async () => + 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 { isDarkMode } = useThemeMode(); const store = useCreateStore(); const { width, avatarSize } = useControls( @@ -26,15 +44,19 @@ export default () => { return ( -
- -
+ {isLoading ? ( + + ) : ( +
+ +
+ )}
); }; diff --git a/src/Sponsor/index.tsx b/src/Sponsor/index.tsx index a3a97a0..d216c9c 100644 --- a/src/Sponsor/index.tsx +++ b/src/Sponsor/index.tsx @@ -29,8 +29,6 @@ const Sponsor: FC = ({ const sponsorData = formateSponsorData(data); - console.log(sponsorData); - return (
= ({ }} > {tierConfig.emoji} - {item.name.length > 8 ? item.name.slice(0, 7) + '...' : item.name} + {item?.name?.length > 8 ? item.name.slice(0, 7) + '...' : item.name}
); diff --git a/src/components/Markdown/index.tsx b/src/components/Markdown/index.tsx index 8a91c53..f4ff667 100644 --- a/src/components/Markdown/index.tsx +++ b/src/components/Markdown/index.tsx @@ -4,7 +4,6 @@ import ReactMarkdown from 'react-markdown'; import rehypeHighlight from 'rehype-highlight'; import rehypeRaw from 'rehype-raw'; import remarkGfm from 'remark-gfm'; -import remarkSlug from 'remark-slug'; import remarkToc from 'remark-toc'; import HighlightStyle from './HighlightStyle'; @@ -19,7 +18,7 @@ export interface MarkdownProps { const Markdown = memo(({ children, className, style, ...props }) => { const { styles, cx } = useStyles(); const rehypePlugins = [rehypeRaw, [rehypeHighlight, { ignoreMissing: true }]] as any; - const remarkPlugins = [remarkGfm, remarkToc, remarkSlug]; + const remarkPlugins = [remarkGfm, remarkToc]; return (
diff --git a/src/services/sponsorkit/github/get-past-sponsors.ts b/src/services/sponsorkit/github/get-past-sponsors.ts deleted file mode 100644 index b71abfe..0000000 --- a/src/services/sponsorkit/github/get-past-sponsors.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { parse } from 'node-html-parser'; - -import type { Sponsorship } from '../types'; - -export interface GetPastSponsorsOptions { - /** - * @default false - */ - includePrivate?: boolean; -} - -function pickSponsorsInfo(html: string): Sponsorship[] { - const root = parse(html); - const baseDate = new Date('2000-1-1'); - const sponsors = root.querySelectorAll('div').map((el) => { - const isPublic = el.querySelector('img'); - const name = isPublic ? isPublic?.getAttribute('alt')?.replace('@', '') : 'Private Sponsor'; - const avatarUrl = isPublic ? isPublic?.getAttribute('src') : ''; - const login = isPublic - ? el.querySelector('a')?.getAttribute('href')?.replace('/', '') - : undefined; - const type = el - .querySelector('a') - ?.getAttribute('data-hovercard-type') - ?.replace(/^\S/, (s) => s.toUpperCase()); - - return { - createdAt: baseDate.toUTCString(), - isOneTime: undefined, - monthlyDollars: -1, - privacyLevel: isPublic ? 'PUBLIC' : 'PRIVATE', - sponsor: { - __typename: undefined, - avatarUrl, - linkUrl: `https://github.com/${name}`, - login, - name, - type, - }, - tierName: undefined, - } as Sponsorship; - }); - - return sponsors; -} - -export async function getPastSponsors(username: string): Promise { - const allSponsors: Sponsorship[] = []; - let newSponsors = []; - let cursor = 1; - - do { - const res = await fetch( - `https://github.com/sponsors/${username}/sponsors_partial?filter=inactive&page=${cursor++}`, - { method: 'GET' }, - ); - const content = await res.text(); - newSponsors = pickSponsorsInfo(content); - allSponsors.push(...newSponsors); - } while (newSponsors.length); - - return allSponsors; -} diff --git a/src/services/sponsorkit/github/index.ts b/src/services/sponsorkit/github/index.ts index 8b08cc2..27a5d5e 100644 --- a/src/services/sponsorkit/github/index.ts +++ b/src/services/sponsorkit/github/index.ts @@ -1,5 +1,4 @@ import type { Provider, SponsorkitConfig, Sponsorship } from '../types'; -import { getPastSponsors } from './get-past-sponsors'; import { makeQuery } from './makeQuery'; const API = 'https://api.github.com/graphql'; @@ -19,7 +18,7 @@ export async function fetchGitHubSponsors( let cursor; do { - const query = makeQuery(login, type, cursor); + const query = makeQuery(login, type, !config.includePastSponsors, cursor); const res = await fetch(API, { body: JSON.stringify({ query }), headers: { @@ -59,14 +58,6 @@ export async function fetchGitHubSponsors( }), ); - if (config.includePastSponsors) { - try { - processed.push(...(await getPastSponsors(login))); - } catch (error) { - console.error('Failed to fetch past sponsors:', error); - } - } - return processed; } diff --git a/src/services/sponsorkit/github/makeQuery.ts b/src/services/sponsorkit/github/makeQuery.ts index 088309f..751f550 100644 --- a/src/services/sponsorkit/github/makeQuery.ts +++ b/src/services/sponsorkit/github/makeQuery.ts @@ -1,9 +1,9 @@ const graphql = String.raw; -export function makeQuery(login: string, type: string, cursor?: string) { +export function makeQuery(login: string, type: string, activeOnly = true, cursor?: string) { return graphql`{ - ${type}(login: "${login}") { - sponsorshipsAsMaintainer(first: 100${cursor ? ` after: "${cursor}"` : ''}) { + ${type}(login: "${login}") { + sponsorshipsAsMaintainer(activeOnly: ${Boolean(activeOnly)}, first: 100${cursor ? ` after: "${cursor}"` : ''}) { totalCount pageInfo { endCursor @@ -12,6 +12,7 @@ export function makeQuery(login: string, type: string, cursor?: string) { nodes { createdAt privacyLevel + isActive tier { name isOneTime @@ -36,5 +37,5 @@ export function makeQuery(login: string, type: string, cursor?: string) { } } } - }`; +}`; }