How To: Write Cross-Document Links
How to Write Cross-Document Links
When writing markdown documentation that will be processed by DocBuilder, you have three options for linking between documents.
Design Goal: Dual Compatibility
DocBuilder’s link transformation system is designed so your documentation works in both contexts:
- In the source forge (GitHub, GitLab, Forgejo) - Links work correctly when viewing files directly in the repository web interface
- In the generated Hugo site - The same links are transformed to work with Hugo’s URL structure
This dual compatibility means you can write standard relative markdown links (like [guide](/docbuilder/guide)) and they’ll work correctly when:
- Developers browse documentation directly in GitHub/GitLab
- Users view the rendered documentation site
- Documentation is reviewed in pull requests/merge requests
The transform pipeline automatically rewrites links during the build process. You write links once, and they work everywhere.
Link Types
1. Page-Relative Links (Recommended for Nearby Files)
Use relative paths from the current file’s location. These work like standard filesystem paths.
Best for: Links to files in the same directory or nearby directories.
2. Repository-Root-Relative Links (Recommended for Cross-Section Links)
Use paths starting with / to link from the repository root, regardless of where the current file is located.
Best for: Links between different major sections of documentation, deep directory structures, or when you want stable links that don’t break if files move.
Important: Repository-root-relative links are relative to your repository’s root, not the Hugo site root. DocBuilder automatically prefixes them with the repository (and forge, if applicable) during processing.
3. Absolute Hugo Links (For Advanced Users)
Use the full Hugo path including the repository name. Only necessary if linking between different repositories in a multi-repo documentation site.
Best for: Cross-repository links in multi-repo documentation sites.
Link Syntax Rules
Extension Handling
DocBuilder automatically removes .md and .markdown extensions and adds trailing slashes for Hugo’s pretty URLs:
Anchor Support
Anchors (fragments) are preserved:
Unchanged Links
These link types are never modified:
- External links:
https://example.com/page.md - Email links:
mailto:user@example.com - Anchor-only links:
#section-heading - Non-markdown links:
image.png,document.pdf
Common Patterns
Linking from Tutorials to How-Tos
If your repository has this structure:
From tutorials/getting-started.md:
Linking Within the Same Section
Linking to Index Pages
Troubleshooting
Links Break When Files Move
Problem: You used page-relative links, and moving files breaks the references.
Solution: Use repository-root-relative links (starting with /) for stability:
Wrong Path in Generated Site
Problem: Link resolves to /repo/tutorials/how-to/authentication/ instead of /repo/how-to/authentication/
Cause: Using page-relative link from tutorials/ directory without going up first.
Solution: Either use ../how-to/authentication.md or use repository-root-relative /how-to/authentication.md.
Link Works in Source but Not in Hugo Site
Problem: Repository-root-relative link works in source repo but not in DocBuilder output.
Cause: Links starting with / are treated as repository-root-relative and automatically prefixed.
Solution: This is expected behavior. DocBuilder handles the prefixing automatically.
Best Practices
- Use repository-root-relative links (
/section/file.md) for major cross-section navigation - Use page-relative links (
file.md,../section/file.md) for nearby files in the same section - Always use
.mdextension in source markdown - DocBuilder removes it automatically - Don’t worry about trailing slashes - DocBuilder adds them automatically
- Test in preview before deploying to ensure links work as expected