mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
fix(frontend): give the embed snippet somewhere to paste.
The result screen ended at the snippet and a copy button. GitHub only renders a profile README from the repo named exactly after the account, and 15 of 23 arrivals did not have that repo, so the copy button was a dead end for most people. Add two links under the snippet: open the README, or create the repo. Also serve a placeholder card instead of a JSON 400 when someone pastes the README snippet without swapping YOUR_USERNAME for their own name, and show a live example card in the README. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS
This commit is contained in:
@@ -8,6 +8,10 @@ your account, charts your contribution timeline, highlights your top
|
|||||||
collaborators, breaks down your languages, tracks your commit streaks,
|
collaborators, breaks down your languages, tracks your commit streaks,
|
||||||
and earns you tags like `Backend`, `ML`, or `Founder #42`.
|
and earns you tags like `Backend`, `ML`, or `Founder #42`.
|
||||||
|
|
||||||
|
[](https://gh-stats.com)
|
||||||
|
|
||||||
|
That card is live, not a screenshot. Swap in your own username:
|
||||||
|
|
||||||
```md
|
```md
|
||||||

|

|
||||||
```
|
```
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ export function ResultScreen({ username, generating, generatedSvg, generateError
|
|||||||
const fallbackUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
|
const fallbackUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
|
||||||
const finalUrl = embedUrl || fallbackUrl
|
const finalUrl = embedUrl || fallbackUrl
|
||||||
const embedSnippet = `[](${window.location.origin})`
|
const embedSnippet = `[](${window.location.origin})`
|
||||||
|
// The snippet is useless without somewhere to paste it: GitHub only renders a
|
||||||
|
// profile README from the repo named exactly after the account. Most people
|
||||||
|
// arriving here don't have that repo yet, so offer both paths.
|
||||||
|
const profileRepo = encodeURIComponent(username)
|
||||||
|
const editReadmeUrl = `https://github.com/${profileRepo}/${profileRepo}/edit/main/README.md`
|
||||||
|
const createRepoUrl = `https://github.com/new?name=${profileRepo}&description=${encodeURIComponent('My GitHub profile')}&visibility=public`
|
||||||
|
|
||||||
const copy = async () => {
|
const copy = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -148,6 +154,12 @@ export function ResultScreen({ username, generating, generatedSvg, generateError
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<p className="mt-3 text-xs text-gray-500">
|
||||||
|
Paste it into <code className="text-gray-600">{username}/{username}</code>, the repo GitHub shows on your profile.{' '}
|
||||||
|
<a href={editReadmeUrl} target="_blank" rel="noopener noreferrer" className="text-gray-700 underline hover:text-gray-900">Open your README</a>
|
||||||
|
{' \u00b7 '}
|
||||||
|
<a href={createRepoUrl} target="_blank" rel="noopener noreferrer" className="text-gray-700 underline hover:text-gray-900">Create the repo</a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -709,10 +709,20 @@ def internal_analytics_events():
|
|||||||
return jsonify({"ingested": n})
|
return jsonify({"ingested": n})
|
||||||
|
|
||||||
|
|
||||||
|
# Literal placeholders from the README snippets. Lowercased because the
|
||||||
|
# username normaliser lowercases before this is reached.
|
||||||
|
_DOC_PLACEHOLDERS = {"your_username", "yourusername", "your-username", "username"}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/<username>", methods=["GET"])
|
@app.route("/api/<username>", methods=["GET"])
|
||||||
@track_request("composite")
|
@track_request("composite")
|
||||||
@rate_limited("read")
|
@rate_limited("read")
|
||||||
def get_widget(username: str):
|
def get_widget(username: str):
|
||||||
|
if username.lower() in _DOC_PLACEHOLDERS:
|
||||||
|
# People paste the README snippet without swapping YOUR_USERNAME for
|
||||||
|
# their own name, so GitHub renders a broken image on their profile.
|
||||||
|
# A card that says what to do is more use to them than a JSON 400.
|
||||||
|
return _placeholder_response("unsubstituted", username)
|
||||||
if not is_valid_username(username):
|
if not is_valid_username(username):
|
||||||
return jsonify({"error": "invalid_username"}), 400
|
return jsonify({"error": "invalid_username"}), 400
|
||||||
return _serve(username, widget_name="composite")
|
return _serve(username, widget_name="composite")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ _MESSAGES = {
|
|||||||
"building": ("Building @{u}'s widget\u2026", "This usually takes under a minute."),
|
"building": ("Building @{u}'s widget\u2026", "This usually takes under a minute."),
|
||||||
"rate_limited": ("Too many new users today", "Try again tomorrow."),
|
"rate_limited": ("Too many new users today", "Try again tomorrow."),
|
||||||
"not_found": ("GitHub user @{u} doesn't exist", "Check the spelling of the username."),
|
"not_found": ("GitHub user @{u} doesn't exist", "Check the spelling of the username."),
|
||||||
|
"unsubstituted": ("Replace YOUR_USERNAME in the URL", "Put your own GitHub username there, e.g. /api/octocat."),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -458,6 +458,20 @@ def test_data_unknown_user_enrolls_when_under_both_caps(client, monkeypatch):
|
|||||||
assert dbmod.get_settings("testuser") is not None
|
assert dbmod.get_settings("testuser") is not None
|
||||||
|
|
||||||
|
|
||||||
|
# ---- README snippet pasted without substituting the username ----
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("name", ["YOUR_USERNAME", "your_username", "yourusername", "username"])
|
||||||
|
def test_unsubstituted_placeholder_returns_card_not_400(client, name):
|
||||||
|
"""The README snippet uses YOUR_USERNAME. People paste it as-is, which
|
||||||
|
renders a broken image on their profile. Serve instructions instead."""
|
||||||
|
r = client.get(f"/api/{name}")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.mimetype == "image/svg+xml"
|
||||||
|
assert r.headers["X-Widget-Status"] == "unsubstituted"
|
||||||
|
assert b"Replace YOUR_USERNAME" in r.data
|
||||||
|
|
||||||
|
|
||||||
# ---- /api/top-langs compat shim for upstream github-readme-stats URLs ----
|
# ---- /api/top-langs compat shim for upstream github-readme-stats URLs ----
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ def test_attribution_is_legible_and_consistent(name):
|
|||||||
assert node.get("text-anchor") == "middle"
|
assert node.get("text-anchor") == "middle"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("variant", ["building", "rate_limited", "not_found"])
|
@pytest.mark.parametrize("variant", ["building", "rate_limited", "not_found", "unsubstituted"])
|
||||||
def test_placeholder_cards_have_attribution(variant):
|
def test_placeholder_cards_have_attribution(variant):
|
||||||
svg = placeholder.render(variant, "alice", theme="dark")
|
svg = placeholder.render(variant, "alice", theme="dark")
|
||||||
assert "Generated with gh-stats.com" in svg
|
assert "Generated with gh-stats.com" in svg
|
||||||
|
|||||||
Reference in New Issue
Block a user