forked from tldraw/tldraw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Sponsors in README (tldraw#301)
* Add images, read me links * Add API route for sponsor image * Update cache max age
- Loading branch information
1 parent
eb20f1c
commit cd48b67
Showing
15 changed files
with
177 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ coverage | |
apps/www/public/worker-* | ||
apps/www/public/sw.js | ||
apps/www/public/sw.js.map | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
const AV_SIZE = 32 | ||
const PADDING = 4 | ||
const COLS = 16 | ||
|
||
type SponsorResult = { url: string; login: string } | ||
type QueryResult = { | ||
node: { sponsorEntity: { avatarUrl: string; login: string } } | ||
} | ||
|
||
function getXY(i: number) { | ||
return [(i % COLS) * (AV_SIZE + PADDING), Math.floor(i / COLS) * (AV_SIZE + PADDING)] | ||
} | ||
|
||
export default async function GetSponsors(req: NextApiRequest, res: NextApiResponse) { | ||
const sponsorInfo = await fetch('https://api.github.com/graphql', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: 'bearer ' + process.env.GITHUB_API_SECRET, | ||
}, | ||
body: JSON.stringify({ | ||
query: `{ | ||
viewer { | ||
sponsors(first: 0) { | ||
totalCount | ||
} | ||
sponsorshipsAsMaintainer(first: 100, orderBy: { | ||
field:CREATED_AT, | ||
direction:DESC | ||
}) { | ||
edges { | ||
node { | ||
sponsorEntity { | ||
...on User { | ||
avatarUrl | ||
login | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`, | ||
}), | ||
}).then((res) => res.json()) | ||
|
||
const totalCount: number = sponsorInfo.data.viewer.sponsors.totalCount | ||
|
||
const results = ( | ||
sponsorInfo.data.viewer.sponsorshipsAsMaintainer.edges as QueryResult[] | ||
).map<SponsorResult>((edge) => ({ | ||
url: edge.node.sponsorEntity.avatarUrl?.replaceAll('&', '&') ?? '', | ||
login: edge.node.sponsorEntity.login, | ||
})) | ||
|
||
if (results.length % COLS <= 2) { | ||
results.pop() | ||
results.pop() | ||
results.pop() | ||
} | ||
|
||
// Avatars | ||
|
||
const avatars = results | ||
.map(({ url, login }, i) => { | ||
const [x, y] = getXY(i) | ||
return `<image alt="${login}" href="${url}" x="${x}" y="${y}" width="${AV_SIZE}" height="${AV_SIZE}"/>` | ||
}) | ||
.join('') | ||
|
||
// More text | ||
|
||
const [x, y] = getXY(results.length) | ||
const width = (AV_SIZE + PADDING) * 3 | ||
const more = ` | ||
<g transform="translate(${x},${y})"><text text-lenth="${width}" font-family="Arial" font-size="12px" font-weight="bold" text-anchor="middle" text-align="center" x="${ | ||
width / 2 | ||
}" y="${AV_SIZE / 2 + 3}">...and ${totalCount - 100} more!</text></g>` | ||
|
||
const svgImage = ` | ||
<svg xmlns="http://www.w3.org/2000/svg"><a href="https://github.com/sponsors/steveruizok"><g>${avatars}${more}</g></a></svg>` | ||
|
||
// const html = ` | ||
// <div style="display: grid; width: fit-content; grid-template-columns: repeat(25, auto); gap: 4px;"> | ||
// ${images.join(` | ||
// `)} | ||
// </div>` | ||
|
||
res | ||
.status(200) | ||
.setHeader('Cache-Control', 'max-age=604800') | ||
.setHeader('Content-Type', 'image/svg+xml') | ||
.send(svgImage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const whitelist = ['steveruizok'] | ||
|
||
export async function isSponsoringMe(login: string) { | ||
if (whitelist.includes(login)) return true | ||
|
||
const res = await fetch('https://api.github.com/graphql', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: 'bearer ' + process.env.GITHUB_API_SECRET, | ||
}, | ||
body: JSON.stringify({ | ||
query: ` | ||
query { | ||
user(login: "steveruizok") { | ||
isSponsoredBy(accountLogin: "${login}") | ||
} | ||
} | ||
`, | ||
}), | ||
}).then((res) => res.json()) | ||
|
||
return res?.data?.user?.isSponsoredBy | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters