VitePress Sidebar - Hybrid Auto-Generation Approach โ
Overview โ
The VitePress sidebar configuration now uses a hybrid approach that combines:
- Manual curation for high-level structure, ordering, and special sections
- Automatic generation for subdirectories to reduce maintenance burden
This gives us the best of both worlds: โ Control over navigation structure and presentation โ Automatic discovery of new documentation files โ Consistent formatting and titling โ Reduced manual maintenance
How It Works โ
Auto-Generation Helper: sidebar.mjs โ
The /docs/.vitepress/sidebar.mjs file provides utility functions:
autoGenerateSidebarItems(dir, options)- Generates sidebar items from markdown files in a directoryautoGenerateNestedSidebar(dir, options)- Generates nested sidebar from directory structureformatTitle(fileName)- Converts filenames to human-readable titles
Configuration: config.mjs โ
The main configuration file imports these helpers and uses them selectively:
import { autoGenerateSidebarItems } from './sidebar.mjs'
// Manual top-level structure
sidebar: [
{
text: 'โ๏ธ Engineering',
items: [
{
text: '๐๏ธ Architecture',
collapsed: false,
// Auto-generate from /docs/engineering/architecture/*.md
items: autoGenerateSidebarItems('engineering/architecture')
}
]
}
]What's Auto-Generated โ
The following sections are automatically generated from directory contents:
Engineering Subdirectories โ
- โ
Architecture (
engineering/architecture/) - โ
Deployment (
engineering/deployment/) - โ
Security (
engineering/security/) - โ
Mobile (
engineering/mobile/) - โ
Testing (
engineering/testing/) - โ
Guides (
engineering/guides/)
Feature Subdirectories โ
- โ
Safety Mechanics (
features/safety/) - โ
Frens System (
features/frens/) - โ
Profile System (
features/profile/) - โ
Wave-to-Meet (
features/wave/) - โ
Lantern Hub (
features/lantern-hub/)
Other Sections โ
- โ
Storybook (
storybook/) - โ
Governance (
governance/) - โ
Security (
security/) - โ
Development Log (
worklog/) - โ
Audits (
audit/)
What's Still Manual โ
The following remain manually curated:
Top-Level Structure โ
- Section ordering (Getting Started โ Engineering โ Features โ etc.)
- Section titles and emoji icons
- Collapsed/expanded states
- Root-level files (ABOUT, CONTRIBUTING, TODO)
Special Sections โ
- Getting Started - Carefully curated onboarding flow
- Features (root) - Top-level feature overview files
- Business - Strategic documents
- Economics - Financial models
- Design - Design system docs
- Development - Contributing, TODO, sitemap
Adding New Documentation โ
For Auto-Generated Sections โ
Simply add a markdown file to the appropriate directory:
# Add a new architecture doc
touch docs/engineering/architecture/NEW_CONCEPT.md
# It will automatically appear in the sidebar on next build!Custom Sorting โ
Some sections have custom sort orders defined:
autoGenerateSidebarItems('engineering/architecture', {
sortFn: (a, b) => {
// SCAFFOLD first, then alphabetical
if (a === 'SCAFFOLD.md') return -1
if (b === 'SCAFFOLD.md') return 1
return a.localeCompare(b)
}
})Excluding Files โ
You can exclude specific files from auto-generation:
autoGenerateSidebarItems('governance', {
excludeFiles: ['SECURITY.md'] // Goes in different section
})Title Formatting Rules โ
The formatTitle() function automatically:
Removes common prefixes/suffixes:
QUICK_START_*โ "Quick Start: *"*_GUIDEโ "* Guide"*_REFโ "* Reference"*_SUMMARYโ "* Summary"
Converts underscores/hyphens to spaces:
ZERO_KNOWLEDGE_ENCRYPTIONโ "Zero Knowledge Encryption"
Capitalizes words intelligently:
- Keeps acronyms uppercase: API, PWA, IP, SOS, etc.
- Title-cases other words
Examples โ
Input Filename โ Output Title โ
SCAFFOLD.mdโ "Scaffold"QUICK_START_DOCS.mdโ "Quick Start: Docs"ZERO_KNOWLEDGE_ENCRYPTION.mdโ "Zero Knowledge Encryption"DEPLOYMENT_GUIDE.mdโ "Deployment Guide"FRENS_QUICK_REF.mdโ "Frens Quick Reference"PWA_SETUP.mdโ "PWA Setup"
When to Extend Auto-Generation โ
Consider adding more auto-generation when:
- A section has 5+ files - Manual maintenance becomes tedious
- Files follow naming conventions - Auto-formatting works well
- Ordering isn't critical - Alphabetical or simple sort is fine
- New files added frequently - Reduces update friction
When to Keep Manual โ
Keep manual configuration when:
- Order matters significantly - Like Getting Started flow
- Custom grouping needed - Special subsections or categories
- Few files (< 5) - Manual is simpler
- Special formatting - Unique icons, descriptions, or metadata
Maintenance โ
To add a new auto-generated section: โ
- Edit
docs/.vitepress/config.mjs - Replace manual
items: [...]withitems: autoGenerateSidebarItems('path/to/dir') - Add custom
sortFnif needed - Test with
npm run docs:build
To customize title formatting: โ
- Edit
docs/.vitepress/sidebar.mjs - Update
formatTitle()function - Add new patterns or exceptions as needed
Benefits of This Approach โ
โ Reduced maintenance: New files automatically appear โ Consistency: All titles formatted the same way โ Flexibility: Can still manually curate important sections โ Discoverability: Nothing gets forgotten in subdirectories โ Future-proof: Easy to extend or modify automation
Future Enhancements โ
Potential improvements:
- [ ] Auto-generate from frontmatter titles (if present in markdown)
- [ ] Support for multi-level nesting (currently 2 levels max)
- [ ] Tag-based filtering and grouping
- [ ] Automatic "New!" badges for recent files
- [ ] Integration with search for better cross-referencing
Last Updated: 2026-01-10 Approach: Hybrid Manual + Auto-Generated Maintenance Burden: Low ๐