refactor(docs): derive SECTION_ORDER and add build-time assertion#54
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
📝 WalkthroughWalkthroughRefactored ChangesDocumentation Page Structure Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 unit tests (beta)
Review rate limit: 3/10 reviews remaining, refill in 37 minutes and 2 seconds. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/src/pages/docs/[...slug].astro (1)
11-41: ⚡ Quick winAdd a duplicate-ID assertion for
SECTION_CATEGORIESYou already validate existence; add a uniqueness check too. Duplicate ids can produce duplicate
<section id>values and duplicate entries ingetStaticPaths().Suggested patch
const SECTION_ORDER = SECTION_CATEGORIES.flatMap(({ ids }) => ids); + +const duplicateIds = SECTION_ORDER.filter((id, index) => SECTION_ORDER.indexOf(id) !== index); +if (duplicateIds.length > 0) { + throw new Error( + `SECTION_CATEGORIES contains duplicate ids: ${Array.from(new Set(duplicateIds)).join(', ')}` + ); +} // Build-time assertion: validate SECTION_CATEGORIES IDs against discovered slugs const availableSlugs = new Set(Object.keys(pagesBySlug));🤖 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 11 - 41, Add a uniqueness assertion for SECTION_CATEGORIES by scanning all cat.ids and detecting duplicates before building SECTION_ORDER; e.g., iterate SECTION_CATEGORIES and count occurrences of each id (or track a Set) and if any id appears more than once throw an Error listing the duplicate ids and their categories for clarity. Ensure you reference SECTION_CATEGORIES and SECTION_ORDER (and optionally SECTION_CATEGORIES[].ids and SECTION_CATEGORIES[].label) so the check runs at build time alongside the existing availability check and prevents duplicate <section id> and static path entries.
🤖 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 11-41: Add a uniqueness assertion for SECTION_CATEGORIES by
scanning all cat.ids and detecting duplicates before building SECTION_ORDER;
e.g., iterate SECTION_CATEGORIES and count occurrences of each id (or track a
Set) and if any id appears more than once throw an Error listing the duplicate
ids and their categories for clarity. Ensure you reference SECTION_CATEGORIES
and SECTION_ORDER (and optionally SECTION_CATEGORIES[].ids and
SECTION_CATEGORIES[].label) so the check runs at build time alongside the
existing availability check and prevents duplicate <section id> and static path
entries.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6115c383-ec06-4c6a-92f6-e4ea8e57831e
📒 Files selected for processing (1)
docs/src/pages/docs/[...slug].astro
|
Fix: Extracted SECTION_CATEGORIES/SECTION_ORDER to sidebar.config.ts. Astro hoists getStaticPaths — only imports survive hoisting. Frontmatter variables were invisible to getStaticPaths causing 'SECTION_ORDER is not defined' build error. |
Summary
SECTION_ORDERfromSECTION_CATEGORIES.flatMap(({ ids }) => ids)— eliminates duplicate hardcoded arraywiki/*.mdfilesORDERwithpagesBySluglookup pattern (was directwikiPagesfile lookup)sectionsToRenderto use{slug, page}tuple patternitem.style.displayand parent displayorderarray ingetStaticPaths()withSECTION_ORDERChanges
docs/src/pages/docs/[...slug].astro: Derive order, add assertion, fix content rendering + searchSummary by CodeRabbit
Release Notes
Bug Fixes
Chores