Add support for _index.md files as repository landing pages
What does this MR do and why?
This was crafted with the help of GitLab Duo Agent.
Adds support for _index.md
files as repository landing pages, making them render automatically alongside README
and index
files.
Changes Made
Backend (Minimal Changes):
-
lib/gitlab/markup_helper.rb
: Added_index
toPLAIN_FILENAMES
array in priority order:%w[readme index _index]
-
Tests: Added
_index
file detection tests tospec/lib/gitlab/file_detector_spec.rb
andspec/models/tree_spec.rb
Frontend (Key Fix):
-
app/assets/javascripts/repository/utils/readme.js
:- Changed
FILENAMES
array to['readme', 'index', '_index']
(priority order) - Rewrote
readmeFile()
function to respect priority order by checking patterns sequentially - Previously used
.find()
which was order-dependent on the blobs array - Now iterates through patterns in priority order, ensuring deterministic selection
- Changed
Documentation:
- Updated
doc/user/project/repository/files/_index.md
to document the new feature and priority order
Priority Order (Deterministic)
- README files (highest priority)
- index files
- _index files (lowest priority)
Within each category:
- Previewable files (with markup extensions like
.md
,.rst
) take precedence over plain text - Alphabetical ordering as tie-breaker (e.g.,
README.adoc
beforeREADME.md
)
Why This Matters
-
Hugo compatibility: Hugo-based projects use
_index.md
for section pages - Deterministic behavior: Frontend now respects priority order regardless of filesystem ordering
-
Backward compatible: Existing
README
andindex
files maintain their precedence
References
Discussed in gitlab-environment-toolkit#192 (comment 2771576958) and I thought that would be an easy task. It wasn't
Blast from the past when we did the same with index.md
Screenshots or screen recordings
Before | After |
---|---|
![]() |
![]() |
Test with mixes
How to set up and validate locally
- Set up GDK.
- Check out this branch.
- Create a new project and import by URL the following testing repo:
https://gitlab.com/axil/indexes.git
- Navigate to the various directories and validate it works as expected (
README.md
>index.md
>_index.md
).
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.