Skip to content

Commit 8b046e7

Browse files
committed
Created an npm package from the Starlight GitHub stats plugin: set up TypeScript, build scripts, and tooling. Configured it to be packable and installable locally via .tgz for testing before publishing...
1 parent 9583b29 commit 8b046e7

File tree

13 files changed

+8688
-0
lines changed

13 files changed

+8688
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
dist
3+
*.log
4+
.DS_Store
5+
*.tgz
6+
7+
# Ignore compiled JS files in src (should only be in dist)
8+
src/**/*.js
9+
src/**/*.js.map
10+

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
src
2+
scripts
3+
tsconfig.json
4+
.gitignore
5+
.npmignore
6+
*.log
7+
.DS_Store
8+

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v24.11.0

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,75 @@
11
# starlight-github-stats
2+
3+
A Starlight plugin to display GitHub repository statistics (stars, forks, and latest version) in the header of your documentation site.
4+
5+
## Features
6+
7+
- ⭐ Display repository star count
8+
- 🔀 Display repository fork count
9+
- 🏷️ Display latest release version
10+
- Automatically fetches live data from GitHub API
11+
- Graceful fallback if API is unavailable
12+
- Responsive design that integrates with Starlight's header
13+
14+
## Installation
15+
16+
```bash
17+
npm install starlight-github-stats
18+
# or
19+
pnpm add starlight-github-stats
20+
# or
21+
yarn add starlight-github-stats
22+
```
23+
24+
## Usage
25+
26+
1. Add the plugin to your `astro.config.mjs`:
27+
28+
```js
29+
import { defineConfig } from "astro/config";
30+
import starlight from "@astrojs/starlight";
31+
import { githubStats } from "starlight-github-stats";
32+
33+
export default defineConfig({
34+
integrations: [
35+
starlight({
36+
plugins: [
37+
githubStats({
38+
repo: "your-username/your-repo", // e.g., "databricks/unity-catalog"
39+
}),
40+
],
41+
}),
42+
],
43+
});
44+
```
45+
46+
2. The plugin will automatically:
47+
- Inject the GitHub stats script
48+
- Add the required CSS styles
49+
- Display stats in the header next to social icons
50+
51+
## Configuration
52+
53+
### Options
54+
55+
- `repo` (required): The GitHub repository in the format `owner/repo`
56+
57+
## How it works
58+
59+
The plugin:
60+
61+
1. Fetches repository data from the GitHub API
62+
2. Fetches the latest release version
63+
3. Formats numbers (e.g., 3100 → 3.1k)
64+
4. Injects the stats into the Starlight header
65+
5. Falls back to static data if the API is unavailable
66+
67+
## Requirements
68+
69+
- Astro ^5.0.0
70+
- @astrojs/starlight ^0.36.0
71+
- Node.js >= 18.0.0
72+
73+
## License
74+
75+
Apache-2.0

eslint.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
4+
import importPlugin from "eslint-plugin-import";
5+
import tseslint from "typescript-eslint";
6+
7+
export default [
8+
{
9+
ignores: ["coverage", "**/dist", "pnpm-lock.yaml", "**/node_modules/**"],
10+
},
11+
{ files: ["**/*.{js,mjs,cjs,ts}"] },
12+
{ languageOptions: { globals: globals.browser } },
13+
{
14+
plugins: {
15+
import: importPlugin,
16+
},
17+
rules: {
18+
"import/export": "error",
19+
"import/no-duplicates": "warn",
20+
"import/order": "error",
21+
},
22+
},
23+
pluginJs.configs.recommended,
24+
eslintPluginPrettierRecommended,
25+
...tseslint.configs.recommended,
26+
];

package.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "starlight-github-stats",
3+
"version": "0.1.0",
4+
"description": "A Starlight plugin to display GitHub repository statistics (stars, forks, version) in the header",
5+
"type": "module",
6+
"main": "./dist/index.js",
7+
"types": "./dist/index.d.ts",
8+
"files": [
9+
"dist",
10+
"README.md",
11+
"LICENSE"
12+
],
13+
"exports": {
14+
".": {
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
17+
},
18+
"./githubStats.css": "./dist/githubStats.css"
19+
},
20+
"scripts": {
21+
"build": "./scripts/build",
22+
"test": "echo \"Error: no test specified\" && exit 1",
23+
"lint": "eslint .",
24+
"lint:fix": "eslint --fix .",
25+
"format": "prettier --check .",
26+
"format:fix": "prettier --write .",
27+
"typecheck": "tsc --noEmit",
28+
"prepack": "pnpm build",
29+
"prepublishOnly": "pnpm build"
30+
},
31+
"peerDependencies": {
32+
"astro": "^5.0.0",
33+
"@astrojs/starlight": "^0.36.0"
34+
},
35+
"devDependencies": {
36+
"@astrojs/starlight": "^0.36.0",
37+
"@eslint/js": "^9.39.1",
38+
"@typescript-eslint/parser": "^8.48.0",
39+
"astro": "^5.0.0",
40+
"eslint": "^9.39.1",
41+
"eslint-config-prettier": "^10.1.8",
42+
"eslint-plugin-import": "^2.32.0",
43+
"eslint-plugin-prettier": "^5.5.4",
44+
"globals": "^16.5.0",
45+
"prettier": "^3.6.2",
46+
"typescript": "^5.9.3",
47+
"typescript-eslint": "^8.48.0"
48+
},
49+
"keywords": [
50+
"astro",
51+
"starlight",
52+
"starlight-plugin",
53+
"github",
54+
"github-stats",
55+
"astro-integration"
56+
],
57+
"author": "Databricks OSS Team",
58+
"license": "Apache-2.0",
59+
"engines": {
60+
"node": ">=18.0.0"
61+
},
62+
"packageManager": "pnpm@10.20.0+sha512.cf9998222162dd85864d0a8102e7892e7ba4ceadebbf5a31f9c2fce48dfce317a9c53b9f6464d1ef9042cba2e02ae02a9f7c143a2b438cd93c91840f0192b9dd"
63+
}

0 commit comments

Comments
 (0)