Skip to content

docs(site): show release version and github stars#604

Merged
jdx merged 2 commits intomainfrom
codex/release-version-title
Apr 25, 2026
Merged

docs(site): show release version and github stars#604
jdx merged 2 commits intomainfrom
codex/release-version-title

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented Apr 25, 2026

Summary

  • read the latest site release label from usage/lib/Cargo.toml and show it as the releases nav item
  • add a GitHub star counter to the VitePress social nav, matching the existing aube/mise pattern

Validation

  • npm run docs:build in /home/jdx/src/usage-release-version

This PR was generated by Codex.


Note

Low Risk
Low risk docs-only changes; main risk is minor build/CI variability from parsing lib/Cargo.toml and 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-parsing lib/Cargo.toml at build time.

Adds a GitHub star counter badge under the existing GitHub social link, backed by a new stars.data.ts loader that optionally fetches stargazers_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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.03%. Comparing base (db5274d) to head (3068b8c).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/.vitepress/config.mts Outdated
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*"([^"]+)"/);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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);

Comment thread docs/.vitepress/theme/index.ts Outdated
Comment on lines +36 to +38
setTimeout(addStarCount, 100)
const observer = new MutationObserver(addStarCount)
observer.observe(document.body, { childList: true, subtree: true })
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 25, 2026

Greptile Summary

This PR enhances the docs navbar by reading the version from lib/Cargo.toml at build time (replacing the static "Releases" label with v{version}) and adds an optional GitHub star counter badge to the VitePress social nav, fetched via a data loader only when a token or env flag is present.

Confidence Score: 5/5

Safe 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

Filename Overview
docs/.vitepress/config.mts Reads lib/Cargo.toml at build time with a regex to extract the version, then displays it as v{version} in the nav; falls back to 0.0.0 with a console warning if the regex misses.
docs/.vitepress/stars.data.ts VitePress data loader that fetches GitHub star count at build time when a token or UPDATE_GITHUB_STARS=1 is set; returns empty string fallback so the badge is hidden when the count is unavailable.
docs/.vitepress/theme/index.ts Adds a setup() hook that uses a MutationObserver to inject the star-count badge into the GitHub social link; observer is guarded with onUnmounted but remains live for the whole session when starsData.stars is empty.
docs/.vitepress/theme/custom.css Adds CSS to position and style the star-count badge under the GitHub social icon; hidden on mobile viewports.

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]
Loading

Fix All in Claude Code

Reviews (2): Last reviewed commit: "docs(site): address release nav feedback" | Re-trigger Greptile

Comment thread docs/.vitepress/theme/index.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread docs/.vitepress/theme/index.ts Outdated
@jdx jdx marked this pull request as ready for review April 25, 2026 15:00
@jdx jdx merged commit b32dc5b into main Apr 25, 2026
10 checks passed
@jdx jdx deleted the codex/release-version-title branch April 25, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant