-
Notifications
You must be signed in to change notification settings - Fork 91
feat: replace github star badges with SVG images #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hsluoyz
merged 5 commits into
apache:master
from
cooronx:feat_replace_footer_more_with_text_links
Apr 16, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09c89fa
feat: replace footer star section fetch with generated JSON
cooronx 9d72dda
feat: remove Baidu script in footer
cooronx 438b7c5
feat: replace index keys in footer links
cooronx f621ea2
feat: use smaller stable keys for footer items
cooronx c7a3592
feat: xtract footer badges into svg icon components
cooronx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,90 @@ | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| const badges = require("../src/components/FooterMoreBadges/badges.json"); | ||
|
|
||
| const outputPath = path.join( | ||
| __dirname, | ||
| "..", | ||
| "src", | ||
| "components", | ||
| "FooterMoreBadges", | ||
| "stars.json" | ||
| ); | ||
|
|
||
| function getRepoKey(owner, repo) { | ||
| return `${owner}/${repo}`; | ||
| } | ||
|
|
||
| function readExistingStars() { | ||
| if (!fs.existsSync(outputPath)) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| return JSON.parse(fs.readFileSync(outputPath, "utf8")); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| async function fetchStars() { | ||
| const headers = { | ||
| Accept: "application/vnd.github+json", | ||
| "User-Agent": "casbin-website-footer-stars", | ||
| }; | ||
|
|
||
| if (process.env.GITHUB_TOKEN) { | ||
| headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`; | ||
| } | ||
|
|
||
| const results = await Promise.all( | ||
| badges.map(async({owner, repo}) => { | ||
| const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`, { | ||
| headers, | ||
| }); | ||
|
cooronx marked this conversation as resolved.
|
||
|
|
||
| if (!response.ok) { | ||
| const body = await response.text(); | ||
| throw new Error(`Failed to fetch stars for ${owner}/${repo}: ${response.status} ${body}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| if (typeof data.stargazers_count !== "number") { | ||
| throw new Error(`Missing stargazers_count for ${owner}/${repo}`); | ||
| } | ||
|
|
||
| return [getRepoKey(owner, repo), data.stargazers_count]; | ||
| }) | ||
| ); | ||
|
|
||
| return Object.fromEntries(results); | ||
| } | ||
|
|
||
| async function main() { | ||
| const existingStars = readExistingStars(); | ||
|
|
||
| try { | ||
| const stars = await fetchStars(); | ||
| const payload = { | ||
| generatedAt: new Date().toISOString(), | ||
| stars, | ||
| }; | ||
|
|
||
| fs.writeFileSync(outputPath, `${JSON.stringify(payload, null, 2)}\n`); | ||
| process.stdout.write(`Updated footer stars at ${outputPath}\n`); | ||
| } catch (error) { | ||
| if (existingStars?.stars) { | ||
| process.stderr.write(`${error.message}\nUsing existing footer stars JSON.\n`); | ||
| return; | ||
| } | ||
|
|
||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| process.stderr.write(`${error.stack || error}\n`); | ||
| process.exit(1); | ||
| }); | ||
This file contains hidden or 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,50 @@ | ||
| [ | ||
| { | ||
| "label": "Casbin", | ||
| "owner": "casbin", | ||
| "repo": "casbin", | ||
| "href": "https://github.com/casbin/casbin" | ||
| }, | ||
| { | ||
| "label": "jCasbin", | ||
| "owner": "casbin", | ||
| "repo": "jcasbin", | ||
| "href": "https://github.com/casbin/jcasbin" | ||
| }, | ||
| { | ||
| "label": "Node-Casbin", | ||
| "owner": "casbin", | ||
| "repo": "node-casbin", | ||
| "href": "https://github.com/casbin/node-casbin" | ||
| }, | ||
| { | ||
| "label": "PHP-Casbin", | ||
| "owner": "php-casbin", | ||
| "repo": "php-casbin", | ||
| "href": "https://github.com/php-casbin/php-casbin" | ||
| }, | ||
| { | ||
| "label": "PyCasbin", | ||
| "owner": "casbin", | ||
| "repo": "pycasbin", | ||
| "href": "https://github.com/casbin/pycasbin" | ||
| }, | ||
| { | ||
| "label": "Casbin.NET", | ||
| "owner": "casbin", | ||
| "repo": "Casbin.NET", | ||
| "href": "https://github.com/casbin/Casbin.NET" | ||
| }, | ||
| { | ||
| "label": "Casbin-CPP", | ||
| "owner": "casbin", | ||
| "repo": "casbin-cpp", | ||
| "href": "https://github.com/casbin/casbin-cpp" | ||
| }, | ||
| { | ||
| "label": "Casbin-RS", | ||
| "owner": "casbin", | ||
| "repo": "casbin-rs", | ||
| "href": "https://github.com/casbin/casbin-rs" | ||
| } | ||
| ] |
This file contains hidden or 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,90 @@ | ||
| import React from "react"; | ||
| import styles from "./styles.module.css"; | ||
| import githubBadges from "./badges.json"; | ||
| import starsData from "./stars.json"; | ||
|
|
||
| const GITHUB_BADGES = githubBadges; | ||
| const STAR_COUNTS = starsData.stars ?? {}; | ||
| const STAR_FORMATTER = new Intl.NumberFormat("en-US", { | ||
| notation: "compact", | ||
| compactDisplay: "short", | ||
| maximumFractionDigits: 1, | ||
| }); | ||
|
|
||
| function getRepoKey(owner, repo) { | ||
| return `${owner}/${repo}`; | ||
| } | ||
|
|
||
| function formatStars(count) { | ||
| return STAR_FORMATTER.format(count).replace(/\.0(?=[A-Za-z])/u, "").toLowerCase(); | ||
| } | ||
|
|
||
| function BadgeLink({href, ariaLabel, children}) { | ||
| return ( | ||
| <a | ||
| className={`footer__link-item ${styles.badgeLink}`} | ||
| href={href} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| aria-label={ariaLabel} | ||
| > | ||
| {children} | ||
| </a> | ||
| ); | ||
| } | ||
|
|
||
| function GitHubStarBadge({label, stars}) { | ||
| const safeStars = Number.isFinite(stars) ? stars : 0; | ||
| const formattedStars = formatStars(safeStars); | ||
|
|
||
| return ( | ||
| <span className={styles.badgeSurface} aria-hidden="true"> | ||
| <span className={styles.badgeLabelSection}> | ||
| <img className={styles.badgeIcon} src="/img/footer/github.svg" alt="" /> | ||
| <span className={styles.badgeText}>{label}</span> | ||
| </span> | ||
| <span className={styles.badgeDivider} /> | ||
| <span className={styles.badgeCountSection}>{formattedStars}</span> | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| function XFollowBadge() { | ||
| return ( | ||
| <span className={`${styles.badgeSurface} ${styles.followBadge}`} aria-hidden="true"> | ||
| <img className={styles.badgeIcon} src="/img/footer/x.svg" alt="" /> | ||
| <span className={styles.badgeText}>Follow @casbinHQ</span> | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| function GitHubBadgeLink({badge, stars}) { | ||
| const {label, href} = badge; | ||
|
|
||
| return ( | ||
| <BadgeLink href={href} ariaLabel={`${label} GitHub repository`}> | ||
| <GitHubStarBadge label={label} stars={stars} /> | ||
| </BadgeLink> | ||
| ); | ||
| } | ||
|
|
||
| function XBadgeLink() { | ||
| return ( | ||
| <BadgeLink href="https://twitter.com/casbinHQ" ariaLabel="Follow @casbinHQ on X"> | ||
| <XFollowBadge /> | ||
| </BadgeLink> | ||
| ); | ||
| } | ||
|
|
||
| export default function FooterMoreBadges() { | ||
| return ( | ||
| <div className={styles.badgesGrid}> | ||
| {GITHUB_BADGES.map((badge) => { | ||
| const repoKey = getRepoKey(badge.owner, badge.repo); | ||
|
|
||
| return <GitHubBadgeLink key={repoKey} badge={badge} stars={STAR_COUNTS[repoKey]} />; | ||
| })} | ||
| <XBadgeLink /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,13 @@ | ||
| { | ||
| "generatedAt": "2026-04-13T13:15:04.436Z", | ||
|
cooronx marked this conversation as resolved.
|
||
| "stars": { | ||
| "casbin/casbin": 19992, | ||
| "casbin/jcasbin": 2631, | ||
| "casbin/node-casbin": 2882, | ||
| "php-casbin/php-casbin": 1326, | ||
| "casbin/pycasbin": 1724, | ||
| "casbin/Casbin.NET": 1309, | ||
| "casbin/casbin-cpp": 250, | ||
| "casbin/casbin-rs": 1090 | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.