doc:gen-nav
Generate navigation structure from documentation files
doc:gen-nav
The doc:gen-nav command scans your documentation directory and generates a navigation structure based on file organization and metadata.
Command Syntax
php artisan doc:gen-navWhat It Does
The command performs these operations:
- Scans the documentation directory - Recursively finds all markdown files
- Reads meta.json files - Extracts section metadata (title, description, order)
- Parses frontmatter - Extracts page titles and metadata from markdown
- Builds navigation tree - Organizes pages into hierarchical sections
- Generates navigation.json - Outputs the navigation structure file
Running the Command
Basic usage:
php artisan doc:gen-navOutput:
Scanning documentation directory...
Found 3 sections, 12 pages
ā Navigation generated: resources/markdown/docs/navigation.json
Generated navigation.json
The command creates resources/markdown/docs/navigation.json:
{
"sections": [
{
"title": "Getting Started",
"slug": "getting-started",
"description": "Installation and setup guide",
"order": 1,
"pages": [
{
"title": "Introduction",
"slug": "getting-started",
"description": "Welcome to OI Laravel Documentation",
"url": "/documentation/getting-started"
},
{
"title": "Installation",
"slug": "installation",
"description": "Step-by-step installation and setup guide",
"url": "/documentation/getting-started/installation"
}
]
},
{
"title": "Configuration",
"slug": "configuration",
"description": "Routes, paths, and search settings",
"order": 2,
"pages": [
{
"title": "Configuration",
"slug": "configuration",
"description": "Configure paths, routes, and search settings",
"url": "/documentation/configuration"
}
]
}
]
}Navigation Structure
Sections
Each section represents a directory in your docs folder:
{
"title": "Getting Started", // From meta.json title
"slug": "getting-started", // Auto-derived from folder name
"description": "Installation guide", // From meta.json description
"order": 1, // From meta.json order
"pages": [...] // Array of pages in section
}Pages
Pages within sections:
{
"title": "Installation", // From markdown frontmatter
"slug": "installation", // Auto-derived from filename
"description": "Setup instructions", // From markdown frontmatter
"url": "/documentation/getting-started/installation" // Full route
}When to Regenerate
Run this command when you:
- Add new sections - Create a new folder with markdown files
- Remove sections - Delete a section folder
- Add pages - Create new markdown files
- Delete pages - Remove markdown files
- Change meta.json - Update section metadata
- Rename files/folders - Change file or folder names
- Update frontmatter - Change page titles or descriptions
- Change order values - Modify sorting in meta.json
Example Workflow
Adding a New Page
-
Create the markdown file:
bashtouch resources/markdown/docs/getting-started/troubleshooting.md -
Add content with frontmatter:
yaml--- title: Troubleshooting description: Common issues and solutions order: 3 --- -
Regenerate navigation:
bashphp artisan doc:gen-nav -
The page now appears in navigation and is accessible
Adding a New Section
-
Create the directory:
bashmkdir resources/markdown/docs/advanced -
Create meta.json:
json{ "type": "section", "title": "Advanced", "description": "Advanced topics", "order": 5 } -
Create _index.md:
yaml--- title: Advanced description: Advanced topics and techniques order: 1 --- -
Regenerate:
bashphp artisan doc:gen-nav
Navigation Output Location
The command outputs to:
resources/markdown/docs/navigation.json
This location is configured in config/oi-documentation.php:
'navigation_file' => 'navigation.json',Change the path if needed:
'navigation_file' => 'custom-nav.json', // resources/markdown/docs/custom-nav.jsonNested Sections
The command handles nested sections:
docs/
āāā guides/
ā āāā meta.json
ā āāā _index.md
ā āāā common-tasks/
ā ā āāā meta.json
ā ā āāā _index.md
ā ā āāā installation.md
ā āāā advanced/
ā āāā meta.json
ā āāā _index.md
ā āāā optimization.md
Generates nested structure in navigation.json.
Troubleshooting
"Section has no meta.json"
Warning: A directory lacks meta.json:
ā Section "guides" has no meta.json
Create docs/guides/meta.json to enable this section
Solution: Add meta.json:
echo '{"type":"section","title":"Guides","order":3}' > docs/guides/meta.jsonThen regenerate:
php artisan doc:gen-navMissing Pages in Navigation
Pages might be hidden if:
- Section folder lacks meta.json
- Page lacks a title in frontmatter
- File isn't in a valid section
Check the console output for warnings.
Wrong Order
Ensure order values are numbers in meta.json:
ā "order": 1 // Correct
ā "order": "1" // Incorrect (string)Navigation.json Is Empty
Verify:
- Documentation files exist
- Sections have meta.json
- Pages have frontmatter with title
Run with debug output:
php artisan doc:gen-nav --verboseAutomation
Run automatically in CI/CD pipelines:
# GitHub Actions
- name: Generate Documentation Navigation
run: php artisan doc:gen-navOr as a git hook:
#!/bin/bash
# .git/hooks/post-merge
php artisan doc:gen-navPerformance
For large documentation sets:
- Command completes in milliseconds
- No performance overhead
- Safe to run frequently
Important Notes
Do not manually edit navigation.json ā It's regenerated every time the command runs. Any manual changes will be overwritten.
Use meta.json and frontmatter to control navigation structure, not the JSON file directly.
Integration with Other Commands
Related commands that work with navigation:
# Generate search index (uses navigation)
php artisan doc:gen-index
# Add a new page (can regenerate)
php artisan doc:add-page --regenerate
# Both steps
php artisan doc:gen-nav && php artisan doc:gen-indexNext Steps
After generating navigation:
- Generate Search Index - Index pages for searching
- View Documentation - Visit the docs
- Add Pages - Create more documentation