Skip to content

Plugin Docs CLI: Extract TOC headings at build time#2644

Open
sunker wants to merge 1 commit into
mainfrom
docs-cli/manifest-headings
Open

Plugin Docs CLI: Extract TOC headings at build time#2644
sunker wants to merge 1 commit into
mainfrom
docs-cli/manifest-headings

Conversation

@sunker
Copy link
Copy Markdown
Contributor

@sunker sunker commented May 22, 2026

What this PR does / why we need it:

The Next.js website renders a "Table of contents" for every plugin docs page, listing the h2 and h3 headings in the page. Today those headings are extracted on every page render by re-parsing the full markdown body - a cost paid on the hot path for every page view on grafana.com.

This PR moves heading extraction to build time. The build command in @grafana/plugin-docs-cli now extracts h2/h3 headings from each page and writes them into the generated manifest.json under a new optional headings field on Page. Consumers can then build the TOC straight from the manifest with zero markdown parsing per request.

Extraction reuses parseMarkdown() from @grafana/plugin-docs-parser, so manifest heading IDs match the IDs the same pipeline produces at render time - anchors line up by construction.

Screenshot 2026-05-22 at 10 22 27

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

📦 Published PR as canary version: Canary Versions

✨ Test out this PR locally via:

npm install website@5.6.1-canary.2644.26276784934.0
npm install @grafana/create-plugin@7.6.1-canary.2644.26276784934.0
npm install @grafana/plugin-docs-cli@0.0.11-canary.2644.26276784934.0
npm install @grafana/plugin-docs-parser@0.0.5-canary.2644.26276784934.0
npm install @grafana/plugin-meta-extractor@0.12.3-canary.2644.26276784934.0
# or 
yarn add website@5.6.1-canary.2644.26276784934.0
yarn add @grafana/create-plugin@7.6.1-canary.2644.26276784934.0
yarn add @grafana/plugin-docs-cli@0.0.11-canary.2644.26276784934.0
yarn add @grafana/plugin-docs-parser@0.0.5-canary.2644.26276784934.0
yarn add @grafana/plugin-meta-extractor@0.12.3-canary.2644.26276784934.0

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new patch release.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@sunker sunker changed the title Plugin Docs: Extract TOC headings into the build manifest Plugin Docs: Extract TOC headings at build time May 22, 2026
@sunker sunker self-assigned this May 22, 2026
@sunker sunker moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team May 22, 2026
@sunker sunker added patch Increment the patch version when merged release Create a release when this pr is merged labels May 22, 2026
@sunker sunker marked this pull request as ready for review May 22, 2026 08:26
@sunker sunker requested a review from a team as a code owner May 22, 2026 08:26
@sunker sunker requested review from academo, Copilot, leventebalogh, mckn, s4kh and wbrowne and removed request for a team May 22, 2026 08:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR moves table-of-contents (TOC) heading extraction (h2/h3) from render time to build time by embedding extracted headings into the generated docs manifest.json. It leverages the existing @grafana/plugin-docs-parser pipeline (parseMarkdown) so heading IDs in the manifest match those produced during rendering, ensuring anchors remain consistent.

Changes:

  • Add an optional headings field to the Page type in @grafana/plugin-docs-parser.
  • Extract h2/h3 headings during docs scanning in @grafana/plugin-docs-cli and attach them to each file-backed page.
  • Update scanner tests to validate heading extraction and omission behavior when no h2/h3 exist.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/plugin-docs-parser/src/types.ts Extends Page with optional headings metadata for TOC generation.
packages/plugin-docs-cli/src/scanner.ts Uses parseMarkdown() during scanning to extract and persist h2/h3 headings into the manifest page tree.
packages/plugin-docs-cli/src/scanner.test.ts Adds coverage asserting headings are extracted (and omitted when absent).

@sunker sunker changed the title Plugin Docs: Extract TOC headings at build time Plugin Docs CLI: Extract TOC headings at build time May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Increment the patch version when merged release Create a release when this pr is merged

Projects

Status: 🔬 In review

Development

Successfully merging this pull request may close these issues.

2 participants