Plugin Docs CLI: Extract TOC headings at build time#2644
Open
sunker wants to merge 1 commit into
Open
Conversation
Contributor
Contributor
There was a problem hiding this comment.
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
headingsfield to thePagetype in@grafana/plugin-docs-parser. - Extract h2/h3 headings during docs scanning in
@grafana/plugin-docs-cliand 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
buildcommand in@grafana/plugin-docs-clinow extracts h2/h3 headings from each page and writes them into the generatedmanifest.jsonunder a new optionalheadingsfield onPage. 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.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