fix(docs): extract SECTION_CATEGORIES to sidebar.config.ts for Astro hoisting#55
Conversation
- Add SECTION_ORDER derived from SECTION_CATEGORIES.flatMap
- Add build-time assertion validating category IDs against wiki slugs
- Replace hardcoded ORDER with pagesBySlug lookup pattern
- Update sectionsToRender to use {slug, page} tuple pattern
- Replace hardcoded order array in getStaticPaths with SECTION_ORDER
- Fix search clear to reset item.style.display and parent display
…hoisting getStaticPaths is hoisted by Astro and cannot reference frontmatter variables. Moving SECTION_CATEGORIES and SECTION_ORDER to sidebar.config.ts allows import to survive hoisting, fixing 'SECTION_ORDER is not defined' build error. Also fixes sectionsToRender to use pagesBySlug lookup pattern and search clear to reset item.style.display and parent display.
📝 WalkthroughWalkthroughThis PR refactors the documentation pages to auto-discover wiki markdown files at build time using ChangesWiki Auto-Discovery and Page Rendering
Sequence DiagramsequenceDiagram
participant Build as Build System
participant Wiki as Wiki .md Files
participant Config as SECTION_CATEGORIES
participant Discover as Page Template
participant Cache as pagesBySlug Map
Build->>Wiki: Glob discover *.md
Wiki-->>Build: File paths
Build->>Discover: Create pagesBySlug map
Discover->>Config: Load SECTION_ORDER
Config-->>Discover: Ordered ids
Discover->>Discover: Validate all ids exist in discovered files
Note over Discover: Build-time assertion<br/>throws if missing
Discover->>Cache: Cache pages by slug
Note over Build,Cache: —— Build Time Complete ——
participant Request as Request /docs/:slug
participant Render as Page Renderer
Request->>Render: Route with slug param
Render->>Cache: Lookup sections by SECTION_ORDER
Cache-->>Render: Matching page objects
Render->>Render: Render sections + JSX
Render-->>Request: HTML response
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly Related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Review rate limit: 1/10 review remaining, refill in 53 minutes and 4 seconds. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/src/pages/docs/[...slug].astro (1)
24-34: ⚡ Quick winAdd duplicate-id guard in build-time validation.
The validation currently checks existence only. A duplicate id across categories can still slip through and cause duplicated sections/route params. Add a uniqueness check in the same assertion block.
Suggested patch
const availableSlugs = new Set(Object.keys(pagesBySlug)); +const seenIds = new Set<string>(); for (const cat of SECTION_CATEGORIES) { for (const id of cat.ids) { + if (seenIds.has(id)) { + throw new Error(`Duplicate SECTION_CATEGORIES id detected: "${id}"`); + } + seenIds.add(id); + if (!availableSlugs.has(id)) { const catName = cat.label || 'root'; throw new Error( `SECTION_CATEGORIES references id "${id}" (category: "${catName}") but no matching wiki/${id}.md was found. Available slugs: ${Array.from(availableSlugs).join(', ')}` ); } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/src/pages/docs/`[...slug].astro around lines 24 - 34, The current validation only checks that each id in SECTION_CATEGORIES exists in availableSlugs; add a uniqueness guard that detects duplicate ids across categories by building a frequency map (or a seen Set) while iterating SECTION_CATEGORIES -> cat.ids and throwing an Error if any id appears more than once; include the duplicated id(s) and the associated category labels (use cat.label or 'root') in the error message so the thrown Error from this block (which references availableSlugs, SECTION_CATEGORIES, cat.ids, and cat.label) clearly identifies the duplicates and their categories.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/src/pages/docs/`[...slug].astro:
- Around line 24-34: The current validation only checks that each id in
SECTION_CATEGORIES exists in availableSlugs; add a uniqueness guard that detects
duplicate ids across categories by building a frequency map (or a seen Set)
while iterating SECTION_CATEGORIES -> cat.ids and throwing an Error if any id
appears more than once; include the duplicated id(s) and the associated category
labels (use cat.label or 'root') in the error message so the thrown Error from
this block (which references availableSlugs, SECTION_CATEGORIES, cat.ids, and
cat.label) clearly identifies the duplicates and their categories.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7248bac1-c7e8-4446-94b0-5d04b5f9afb7
📒 Files selected for processing (2)
docs/src/pages/docs/[...slug].astrodocs/src/pages/docs/sidebar.config.ts
…hoisting getStaticPaths is hoisted by Astro and cannot reference frontmatter variables. Moving SECTION_CATEGORIES and SECTION_ORDER to sidebar.config.ts allows import to survive hoisting, fixing 'SECTION_ORDER is not defined' build error.
Problem
Deploy fails with
SECTION_ORDER is not definedduring static route generation.Root Cause
Astro hoists
getStaticPaths()to module scope — it runs BEFORE frontmatter code executes.SECTION_ORDERdefined in frontmatter is invisible togetStaticPaths. Only imports survive hoisting.Fix
SECTION_CATEGORIES+SECTION_ORDERtosidebar.config.ts[...slug].astro— import survives hoistinggetStaticPathsnow references importedSECTION_ORDER— works correctlyFiles
docs/src/pages/docs/sidebar.config.ts(new)docs/src/pages/docs/[...slug].astro(import + remove inline def)Summary by CodeRabbit
Documentation
Bug Fixes