Skip to content

fix(docs): scope heading anchors to API documentation only#1228

Merged
baktun14 merged 1 commit into
mainfrom
fix/scope-heading-anchors-to-api-docs
May 25, 2026
Merged

fix(docs): scope heading anchors to API documentation only#1228
baktun14 merged 1 commit into
mainfrom
fix/scope-heading-anchors-to-api-docs

Conversation

@baktun14
Copy link
Copy Markdown
Contributor

Summary

Fixes the over-scoped rollout from #1227. The shareable # heading anchors were meant to ship only on the API documentation section, but the implementation applied globally:

  • rehype-slug + rehype-autolink-headings ran on every MD/MDX file under src/content/, so headings under developers/, providers/, node-operators/, getting-started/, learn/, and AEPs (src/content/aeps/) all got the # icon injected.
  • The shared docs-layout.astro unconditionally emitted the anchor CSS (including a scroll-margin-top: 7rem rule on every heading with an id) and the clipboard/scroll JS, affecting scroll behaviour across the whole site even on pages with no anchor UI.

Changes

  • New src/lib/markdown/apiDocsOnly.ts — a small unified plugin wrapper that no-ops unless the vfile's source path is inside src/content/Docs/api-documentation/.
  • astro.config.mjs — wrap both rehype plugins with apiDocsOnly(...).
  • src/layouts/docs-layout.astro — derive isApiDocs = Astro.url.pathname.startsWith("/docs/api-documentation/") and gate the <style is:global> + <script> behind it.
  • The manual anchor markup on api-documentation/console-api/api-reference.astro and api-documentation/getting-started.astro is unchanged — both pages already live under the gated path, so the layout's CSS + JS still apply.

Test plan

Verified against the production build (npm run build, 588 pages):

Page heading-anchor count scroll-margin override clipboard JS
docs/developers/contributing 0 0 0
docs/providers/getting-started 0 0 0
docs/getting-started/... 0 0 0
docs/learn/... 0 0 0
docs/node-operators/... 0 0 0
roadmap/aep-64 (and other AEPs) 0 0 0
docs/api-documentation/rest-api/gpu-availability-guide (markdown) 18 1 2
docs/api-documentation/getting-started (custom .astro) 16 1 2
docs/api-documentation/console-api/api-reference (custom .astro) 33 1 2
  • Hover any heading on a non-API docs page — no # icon, no scroll-jump on refresh-with-hash
  • Hover any heading on an API docs page — # appears on hover, click copies the deep-link URL and shows the green check
  • Right-rail TOC still scrolls correctly on non-API pages (Astro's native heading IDs still cover h2–h3, which is what generateToc uses)
  • npm run build succeeds

PR #1227 added rehype-slug + rehype-autolink-headings globally and put the
anchor CSS (including a `scroll-margin-top` on every heading with an id)
plus clipboard/scroll JS in the shared docs layout. As a result the `#`
icon and the scroll override leaked onto every docs page — developers,
providers, getting-started, learn, node-operators, AEPs — when the intent
was to only ship this on the API documentation section.

- Add `apiDocsOnly`, a small unified-plugin wrapper that only delegates
  to the inner plugin when the markdown vfile is under
  `src/content/Docs/api-documentation/`.
- Wrap both rehype plugins with it in `astro.config.mjs`.
- Gate the anchor `<style is:global>` and `<script>` in `docs-layout.astro`
  behind `Astro.url.pathname.startsWith("/docs/api-documentation/")`.

Manual anchor markup on the custom `.astro` pages
(`api-documentation/console-api/api-reference.astro`,
`api-documentation/getting-started.astro`) is unchanged — those pages
already live under the gated path so the layout's CSS + JS still apply.
@baktun14 baktun14 merged commit 9871c87 into main May 25, 2026
1 check failed
baktun14 added a commit that referenced this pull request May 26, 2026
…nchors (#1229)

* fix(docs): restore hover-only # icons, drop h1 anchors

PR #1228 wrapped the heading-anchor `<style is:global>` and `<script>`
in `{isApiDocs && (<tag>{`...`}</tag>)}` JSX conditionals with the
CSS/JS body inside a template literal. Astro's build mangles that
pattern: the production stylesheet truncated to
`.heading-anchor { .heading-anchor:hover,` (so the default
`opacity: 0` rule was missing and # icons rendered fully visible),
and the clipboard/scrollToHash script was dropped from the page
entirely (so refresh-with-hash stopped working).

Move the style and script into a dedicated child component with raw
tag bodies (no template literals); the layout just renders
`{isApiDocs && <HeadingAnchorAssets />}`. Astro processes the tags
correctly through the component boundary.

While here, drop the `<a class="heading-anchor">` wrapper from the
page-title `<h1>`s on `api-reference.astro` and
`getting-started.astro` — anchoring to the page URL itself is
meaningless — and configure `rehype-autolink-headings` with
`test: ["h2", ..., "h6"]` so MD/MDX h1s skip the anchor too.

* fix(docs): drop literal <script>/<style> from frontmatter comment

Astro's component parser was matching the literal `<script>` text
inside the frontmatter JS comment as a real script-tag opening,
sliding the script body's start into the comment text and feeding
"tags directly — wrapping them inside a JSX…" to esbuild, which
then failed: `Expected ";" but found "directly"`. Production
`astro build` happened to ignore it; `astro dev` (Vite dep scan)
surfaced the error.

Rewrite the comment without literal tag names.
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