Skip to content

Commit 2dd3082

Browse files
authored
show stars in header (#1125)
1 parent d3b28a1 commit 2dd3082

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

docs/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
content: "\2197";
2222
}
2323

24+
#observablehq-header a[target="_blank"][data-decoration]::after {
25+
content: attr(data-decoration);
26+
}
27+
2428
#observablehq-header a[target="_blank"]:not(:hover, :focus)::after {
2529
color: var(--theme-foreground-muted);
2630
}

observablehq.config.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import {formatPrefix} from "d3-format";
2+
3+
let stargazers_count: number;
4+
try {
5+
({stargazers_count} = await github("/repos/observablehq/framework"));
6+
} catch (error) {
7+
if (process.env.CI) throw error;
8+
stargazers_count = NaN;
9+
}
10+
111
export default {
212
output: "docs/.observablehq/dist",
313
title: "Observable Framework",
@@ -106,13 +116,31 @@ export default {
106116
<a href="/">
107117
<span class="hide-if-small">Observable</span> Framework
108118
</a>
109-
<span style="display: flex; align-items: baseline; gap: 0.5rem; font-size: 14px;">
110-
<a target="_blank" href="https://github.com/observablehq/framework/releases"><span>${process.env.npm_package_version}</span></a>
111-
<a target="_blank" href="https://github.com/observablehq/framework"><span>GitHub</span></a>
119+
<span style="display: flex; align-items: baseline; gap: 1rem; font-size: 14px;">
120+
<a target="_blank" href="https://github.com/observablehq/framework/releases"><span>${
121+
process.env.npm_package_version
122+
}</span></a>
123+
<a target="_blank" data-decoration="★" href="https://github.com/observablehq/framework"><span>GitHub️ ${
124+
stargazers_count ? formatPrefix(".1s", 1000)(stargazers_count) : ""
125+
}</span></a>
112126
</span>
113127
</div>
114128
</div>`,
115129
footer: ${new Date().getUTCFullYear()} Observable, Inc.`,
116130
style: "style.css",
117131
search: true
118132
};
133+
134+
async function github(
135+
path: string,
136+
{
137+
authorization = process.env.GITHUB_TOKEN && `token ${process.env.GITHUB_TOKEN}`,
138+
accept = "application/vnd.github.v3+json"
139+
} = {}
140+
) {
141+
const url = new URL(path, "https://api.github.com");
142+
const headers = {...(authorization && {authorization}), accept};
143+
const response = await fetch(url, {headers});
144+
if (!response.ok) throw new Error(`fetch error: ${response.status} ${url}`);
145+
return await response.json();
146+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"devDependencies": {
9191
"@types/cross-spawn": "^6.0.6",
9292
"@types/d3-array": "^3.2.1",
93+
"@types/d3-format": "^3.0.4",
9394
"@types/he": "^1.2.3",
9495
"@types/jsdom": "^21.1.6",
9596
"@types/markdown-it": "^13.0.2",
@@ -107,6 +108,7 @@
107108
"chai-http": "^4.4.0",
108109
"concurrently": "^8.2.2",
109110
"d3-dsv": "^3.0.1",
111+
"d3-format": "^3.1.0",
110112
"eslint": "^8.50.0",
111113
"eslint-config-prettier": "^9.1.0",
112114
"eslint-import-resolver-typescript": "^3.6.1",

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@
518518
resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-3.2.1.tgz#1f6658e3d2006c4fceac53fde464166859f8b8c5"
519519
integrity sha512-Y2Jn2idRrLzUfAKV2LyRImR+y4oa2AntrgID95SHJxuMUrkNXmanDSed71sRNZysveJVt1hLLemQZIady0FpEg==
520520

521+
"@types/d3-format@^3.0.4":
522+
version "3.0.4"
523+
resolved "https://registry.yarnpkg.com/@types/d3-format/-/d3-format-3.0.4.tgz#b1e4465644ddb3fdf3a263febb240a6cd616de90"
524+
integrity sha512-fALi2aI6shfg7vM5KiR1wNJnZ7r6UuggVqtDA+xiEdPZQwy/trcQaHnwShLuLdta2rTymCNpxYTiMZX/e09F4g==
525+
521526
"@types/[email protected]", "@types/estree@^1.0.0":
522527
version "1.0.5"
523528
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
@@ -1209,6 +1214,11 @@ d3-dsv@^3.0.1:
12091214
iconv-lite "0.6"
12101215
rw "1"
12111216

1217+
d3-format@^3.1.0:
1218+
version "3.1.0"
1219+
resolved "https://registry.yarnpkg.com/d3-format/-/d3-format-3.1.0.tgz#9260e23a28ea5cb109e93b21a06e24e2ebd55641"
1220+
integrity sha512-YyUI6AEuY/Wpt8KWLgZHsIU86atmikuoOmCfommt0LYHiQSPjvX2AcFc38PX0CBpr2RCyZhjex+NS/LPOv6YqA==
1221+
12121222
d3-require@^1.3.0:
12131223
version "1.3.0"
12141224
resolved "https://registry.yarnpkg.com/d3-require/-/d3-require-1.3.0.tgz#2b97f5e2ebcb64ac0c63c11f30056aea1c74f0ec"

0 commit comments

Comments
 (0)