Index Files
DocBuilder automatically generates index pages for repositories and sections, but also respects user-provided index files. This document explains how index files are discovered, processed, and what takes precedence when multiple options exist.
Overview
DocBuilder generates Hugo _index.md files at three levels:
- Site Level: Main landing page (
content/_index.md) - Repository Level: Repository overview pages (
content/{repository}/_index.md) - Section Level: Section overview pages (
content/{repository}/{section}/_index.md)
Users can provide their own index content to replace auto-generated indexes.
Transform Pipeline Processing
All index files are processed through DocBuilder’s fixed transform pipeline, which applies transformations in a specific order:
- normalizeIndexFiles - Automatically converts
README.md→_index.mdfor Hugo compatibility - buildBaseFrontMatter - Adds default metadata (title, type, date, repository)
- extractIndexTitle - Extracts H1 heading as title for index pages
- rewriteRelativeLinks - Fixes markdown links to work in Hugo (
.md→/, directory-style) - rewriteImageLinks - Corrects image paths relative to content root
- addRepositoryMetadata - Injects repository/forge/commit information
- addEditLink - Generates edit URLs for source links
This ensures all index files (whether user-provided or auto-generated) receive consistent processing and link rewriting.
For more details on the transform pipeline, see Content Transform Pipeline and ADR-003: Fixed Transform Pipeline.
Repository-Level Indexes
At the repository level (directly under the configured paths), DocBuilder supports three scenarios:
Case 1: README.md Only
When a repository contains only a README.md file at the root of the docs path:
Behavior: README.md is automatically normalized to _index.md by the normalizeIndexFiles transform. The transform pipeline then processes it like any other document (link rewriting, metadata injection, etc.).
Case 2: No User-Provided Index
When neither README.md nor index.md exists:
Behavior: DocBuilder auto-generates a repository index listing sections and documents.
Case 3: index.md Only
When a repository contains an index.md file:
Behavior: index.md is automatically normalized to _index.md by the normalizeIndexFiles transform, just like README.md files.
Case 4: Both index.md and README.md
When both files exist at the repository root:
Behavior:
- Both files are discovered and processed through the transform pipeline
index.mdis normalized to_index.mdfirst (takes precedence for the repository index)README.mdis also normalized to_index.mdbut is renamed to prevent collision- The original
README.mdposition in the pipeline ensures it’s accessible at/repo/readme/
Precedence Order: index.md > README.md > auto-generated
Implementation Note: This precedence is handled during the generation phase, before transforms run. The pipeline only receives files that should exist in the final site.
Section-Level Indexes
Within sections (subdirectories), README.md or index.md files are recognized as section indexes:
Behavior: Both README.md and index.md in a section directory are normalized to _index.md by the transform pipeline. If both exist in the same section, index.md takes precedence (same as repository-level).
If no user-provided index exists, the generation phase creates a section index listing all documents in that section. Generated indexes are then processed through the same transform pipeline.
File Naming Conventions
Important notes about file naming:
- Case-Insensitive:
README.md,readme.md,Readme.mdare all treated the same - Lowercase URLs: Files are converted to lowercase for URLs (
README.md→/repo/readme/) - Automatic Normalization: Both
README.mdandindex.mdare automatically converted to_index.mdby thenormalizeIndexFilestransform early in the pipeline - Hugo Compatibility: The
_index.mdnaming is required by Hugo for section/repository index pages
Configuration Impact
Forge-Discovered Repositories
Repositories discovered via forge auto-discovery (GitLab, GitHub, Forgejo) default to using ["docs"] as their documentation paths:
For these repositories, place your index.md or README.md at:
docs/index.md(repository index)docs/section-name/index.md(section index)
Explicitly Configured Repositories
For explicitly configured repositories, you control the documentation paths:
Index files should be placed at the root of each configured path:
documentation/index.mdguides/index.md
Front Matter in User-Provided Indexes
User-provided index files can include Hugo front matter:
If no front matter is present, the buildBaseFrontMatter transform adds it automatically:
Additional metadata is injected by later transforms:
editURL- Added byaddEditLinktransform if repository forge is configured- Repository/commit info - Added by
addRepositoryMetadatatransform
User-provided front matter takes precedence and is merged with auto-generated fields.
Ignored Files
The following files are filtered during discovery and never enter the processing pipeline:
CONTRIBUTING.mdCHANGELOG.mdLICENSE.mdCODE_OF_CONDUCT.md.github/directory contents
These files are typically repository-level documentation not relevant to the generated docs site and are excluded at discovery time regardless of location (root or subdirectories).
Important: README.md is not ignored. It can be used as a repository/section index (automatically normalized to _index.md) or as a regular document depending on the presence of index.md files.
Best Practices
-
Use index.md for Docs Sites: If you’re building a dedicated documentation site, use
index.mdfor repository and section indexes. ReserveREADME.mdfor GitHub/GitLab repository overview. -
Keep README.md for Dual Purpose: If your repository README is also suitable as docs landing page, use
README.mdand skipindex.md. Both are normalized to_index.mdby the pipeline. -
Section Organization: Provide
README.mdorindex.mdfiles in section directories to give users context about what’s in that section. Missing indexes are auto-generated but lack custom content. -
Front Matter: Add proper front matter to control titles, descriptions, and ordering in navigation. The pipeline merges user front matter with auto-generated fields.
-
Relative Links Work: Both user-provided and auto-generated indexes receive link rewriting, so you can use relative markdown links (
[Guide](/docbuilder/reference/guide)) and they’ll be converted to Hugo-compatible URLs automatically.
Examples
Example 1: Technical Documentation with Separate README
Result:
- Site uses
docs/index.mdas repository index - GitHub shows root
README.md - Root
README.mdnot included in docs site
Example 2: Simple Project with README as Docs
Result:
docs/README.mdbecomes repository index- Simple structure for small projects
Example 3: Multi-Language Documentation
Result:
- Clear index pages at each level
- Language sections well-organized
Troubleshooting
Q: My index.md isn’t being used as the repository index
A: Ensure:
- File is at the root of your configured
pathsdirectory - File is named exactly
index.mdorREADME.md(case-insensitive) - File has
.mdor.markdownextension - Repository has been rebuilt (daemon mode requires rebuild trigger)
- Check verbose logs for “normalizeIndexFiles” transform output
Q: Links in my index files aren’t working
A: Index files go through the same link rewriting transforms as regular documents. Use standard markdown links:
- Relative links:
[Guide](/docbuilder/reference/guide)→/repo/guide/ - Section links:
[API](/docbuilder/reference/api/overview)→/repo/api/overview/ - The
rewriteRelativeLinkstransform handles conversion automatically
Q: README.md is missing from my site when I have both README.md and index.md
A: This is expected behavior. When index.md exists at the same level, it takes precedence during the generation phase. README.md may still be accessible as a regular document at /repository/readme/ depending on how the precedence was resolved.
Q: My section index.md isn’t showing up
A: Check that:
- File is in a subdirectory (section), not at repository root
- Section is not empty (contains other .md files)
- File is being discovered (check verbose logs for “Discovered file”)
- Transform pipeline logs show normalization: “normalizeIndexFiles: README → _index”
Q: Front matter from my index file is being overwritten
A: User-provided front matter is merged with auto-generated fields, not replaced. If you see unexpected values:
- Check that your front matter is valid YAML
- Ensure the front matter fence starts at line 1 (no content before
---) - User values take precedence over pipeline defaults
- Some fields (like
editURL) are added by transforms after user front matter is parsed
[index-files](https://docs.home.luguber.info/_uid/7d804d6f-42df-436f-8b7c-cadc4c6b88c4/)