Skip to content

feat(website): add starlight-links-validator to catch broken internal links#119

Merged
afucher merged 6 commits intomainfrom
fix/website-relative-links
Apr 2, 2026
Merged

feat(website): add starlight-links-validator to catch broken internal links#119
afucher merged 6 commits intomainfrom
fix/website-relative-links

Conversation

@afucher
Copy link
Copy Markdown
Contributor

@afucher afucher commented Apr 2, 2026

Summary

  • Installs starlight-links-validator@0.21.0 as a Starlight plugin — validates internal links at build time and fails the build if any are broken
  • Configured with errorOnRelativeLinks: false so all content links stay in relative form (migration to astrochart.dev only requires changing base in astro.config.mjs, no content files touched)
  • Disabled during astro dev to keep local iteration fast; runs only on npm run build
  • Hash fragment validation (#valid-planet-keys) remains active
  • Fixes two pre-existing broken links in guides/frameworks/angular.md and guides/frameworks/vue.md where ../multiple-charts was one level short (correct form is ../../multiple-charts)

Test plan

  • npm run build from website/ completes with All internal links are valid.
  • npm run dev from website/ starts without running the validator
  • npm run build and npm test from repo root still pass (library unaffected)

🤖 Generated with eca

afucher and others added 6 commits April 1, 2026 15:59
GitHub Pages serves every page at a trailing-slash URL (e.g.
/AstroChart/quickstart/). From such a URL, `./guides/foo` resolves
to /AstroChart/quickstart/guides/foo instead of /AstroChart/guides/foo.

Fix all cross-directory relative links on top-level pages to use `../`
instead of `./` when navigating into subdirectories:

- quickstart.mdx: 7 links (Next Steps + Troubleshooting)
- introduction.mdx: 2 links (guides/radix-chart, api/chart)
- installation.md: 5 links (compatibility table + Next Steps)
- changelog.md: 1 dead link replaced (guides/getting-started → ../introduction)

Also:
- astro.config.mjs: remove bare favicon '/favicon.svg' (Starlight
  auto-discovers public/favicon.svg); add trailingSlash: 'always'
  so dev server matches GitHub Pages behavior and catches link bugs early
- AGENTS.md: add 'Website / Astro link strategy' section with a
  per-depth reference table and future domain migration note

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
trailingSlash: 'always' in astro.config.mjs makes the dev server enforce
slash-terminated URLs (mirroring GitHub Pages). withBase was producing
slash-less paths (e.g. /AstroChart/installation) which the strict dev
server no longer matched, breaking the Get Started and other hero links.

Fix: append a trailing slash in withBase if not already present.

  withBase('/installation')  →  '/AstroChart/installation/'

All callers in index.astro are fixed automatically. No other files change.
Edge cases verified:
  base: '/AstroChart'  →  /AstroChart/installation/  ✅
  base: '/'            →  /installation/             ✅  (future astrochart.dev)

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
Root-level pages use trailing-slash URLs (e.g. /AstroChart/introduction/).
./sibling from such a URL resolves to /AstroChart/introduction/sibling —
wrong. All sibling links on root pages must use ../ to reach /AstroChart/sibling.

introduction.mdx: ./installation, ./quickstart (×2), ./contributing → ../
installation.md:  ./quickstart → ../quickstart

These were missed in the first pass which only fixed cross-directory links.
Full project audit confirmed no other broken relative links remain.

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
The link strategy table incorrectly said root pages use './' for sibling
root pages. That was the exact mistake that caused two broken-link passes.
Corrected: root pages use '../' for ALL targets (siblings and subdirs) because
the trailing-slash URL makes the browser treat the page as a directory.

Added an explanatory callout making the 'why' explicit so the rule is
impossible to misread.

Added a mandatory link audit rule: any task touching content files or
trailingSlash/base config must end with a full grep of src/content/docs/
to verify no root-level page retains any './' link.

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
… in dev

Astro markdown pipeline emits relative hrefs verbatim (no trailing slash).
trailingSlash: always makes the dev server 404 every one of the ~50 relative
links in the content tree. GitHub Pages issues a silent 301 for slash-less
URLs in production so links work fine without the strict setting.

AGENTS.md: added explicit do-not-add warning explaining the tension with the
markdown pipeline. Removed the incorrect claim that the setting catches bugs.

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
… links

Install starlight-links-validator@0.21.0 and register it as a Starlight
plugin. Validation runs only on `npm run build` (skipped in dev mode to
keep `astro dev` fast).

Configuration: `errorOnRelativeLinks: false` — all internal links use
relative paths so the site can be migrated to a different base (e.g.
astrochart.dev) by changing only `astro.config.mjs`. Hash fragments
(e.g. `#valid-planet-keys`) are still validated.

Also fixes two pre-existing broken links in guides/frameworks/ where
`../multiple-charts` was one level short and should be `../../multiple-charts`.

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
@afucher afucher merged commit d8fb56f into main Apr 2, 2026
4 checks passed
@afucher afucher deleted the fix/website-relative-links branch April 2, 2026 23:05
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