docs(site): show release version and github stars#604
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #604 +/- ##
=======================================
Coverage 79.03% 79.03%
=======================================
Files 48 48
Lines 7235 7235
Branches 7235 7235
=======================================
Hits 5718 5718
Misses 1140 1140
Partials 377 377 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic versioning for the documentation by extracting the package version from Cargo.toml and adds a GitHub star count badge to the site's social links. The star count is retrieved from the GitHub API with a fallback mechanism and injected into the navigation bar using a MutationObserver. Feedback was provided to improve the robustness of the regex used for version extraction and to optimize the DOM injection logic by removing a redundant timeout and considering a more specific observation target.
| const commands = getCommands(spec.cmd); | ||
| const configDir = dirname(fileURLToPath(import.meta.url)); | ||
| const cargoToml = readFileSync(resolve(configDir, "../../lib/Cargo.toml"), "utf8"); | ||
| const versionMatch = cargoToml.match(/\[package\][\s\S]*?\nversion\s*=\s*"([^"]+)"/); |
There was a problem hiding this comment.
The regex for extracting the version from Cargo.toml is somewhat fragile as it relies on a specific newline sequence and could match commented-out lines if they appear before the actual version definition. A more robust approach for TOML files is to anchor the match to the start of the line and look for the first occurrence of the version key.
const versionMatch = cargoToml.match(/^version\s*=\s*"([^"]+)"/m);
| setTimeout(addStarCount, 100) | ||
| const observer = new MutationObserver(addStarCount) | ||
| observer.observe(document.body, { childList: true, subtree: true }) |
There was a problem hiding this comment.
The setTimeout is redundant because the MutationObserver already handles dynamic updates to the DOM. Additionally, observing the entire document.body with subtree: true can be performance-intensive as it triggers on every mutation. It is recommended to remove the timeout and consider observing a more specific parent element (like the navigation bar) if possible.
| setTimeout(addStarCount, 100) | |
| const observer = new MutationObserver(addStarCount) | |
| observer.observe(document.body, { childList: true, subtree: true }) | |
| const observer = new MutationObserver(addStarCount) | |
| observer.observe(document.body, { childList: true, subtree: true }) |
Greptile SummaryThis PR enhances the docs navbar by reading the version from Confidence Score: 5/5Safe to merge — docs-only change with graceful fallbacks; one minor P2 on unnecessary observer lifetime when stars are unavailable. No P0 or P1 issues found. The single P2 finding (observer set up even when stars data is empty) does not affect correctness or cause user-facing bugs since onUnmounted provides a safety net. All code paths have fallbacks and the build cannot break from missing network or env vars. docs/.vitepress/theme/index.ts — minor observer lifetime concern when starsData.stars is empty. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[npm run docs:build] --> B[config.mts\nreadFileSync lib/Cargo.toml]
B -->|version found| C[nav: v3.x.x]
B -->|not found| D[nav: v0.0.0 + warn]
A --> E[stars.data.ts load]
E -->|GITHUB_TOKEN or GH_TOKEN set| F[fetch api.github.com/repos/jdx/usage]
F -->|ok| G[formatStars → e.g. '1.2k']
F -->|error / rate-limited| H[stars = '']
E -->|no token & UPDATE_GITHUB_STARS≠1| H
G --> I[starsData.stars = '1.2k']
H --> J[starsData.stars = '']
I --> K[theme/index.ts setup\nonMounted]
J --> K
K -->|stars non-empty| L[addStarCount — inject .star-count span]
L -->|VPNav already in DOM| M[badge inserted, observer skipped]
L -->|VPNav not yet rendered| N[MutationObserver watches DOM]
N -->|nav appears| O[badge inserted, observer.disconnect]
K -->|stars empty| P[addStarCount returns false\nobserver created unnecessarily]
Reviews (2): Last reviewed commit: "docs(site): address release nav feedback" | Re-trigger Greptile |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 19f1c5a. Configure here.

Summary
usage/lib/Cargo.tomland show it as the releases nav itemValidation
npm run docs:buildin/home/jdx/src/usage-release-versionThis PR was generated by Codex.
Note
Low Risk
Low risk docs-only changes; main risk is minor build/CI variability from parsing
lib/Cargo.tomland optionally fetching GitHub stars (guarded with fallbacks/timeouts).Overview
Updates the VitePress docs navbar to display the current release label (e.g.
vX.Y.Z) by reading and regex-parsinglib/Cargo.tomlat build time.Adds a GitHub star counter badge under the existing GitHub social link, backed by a new
stars.data.tsloader that optionally fetchesstargazers_count(with token/env gating, timeout, and offline/rate-limit fallback) and new CSS/DOM injection logic in the theme to render it.Reviewed by Cursor Bugbot for commit 3068b8c. Bugbot is set up for automated code reviews on this repo. Configure here.