fix: preserve source order for sidebar subsections - #299
Merged
rich-iannone merged 1 commit intoAug 2, 2026
Conversation
Custom sections with numeric-prefixed subdirectories (01-foundations/,
02-effect-estimation/, ...) rendered their sidebar subsections in
alphabetical order rather than the intended numeric order.
_copy_section_files strips numeric prefixes from subdirectory path
components, so _add_section_sidebar's `sorted(subdir_groups_dict.keys())`
sorted the stripped names ("applied-models" before "foundations") and
discarded the author's ordering.
The source file list is already sorted with prefixes intact, so the
grouping dict's insertion order reflects the intended order. Iterating
the dict directly preserves it.
Adds test_add_section_sidebar_preserves_subdir_order, which fails without
the change and passes with it.
Member
|
Thanks for this PR: really appreciated! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Custom sections with numeric-prefixed subdirectories rendered their sidebar subsections alphabetically instead of in the intended numeric order.
_copy_section_filesstrips numeric prefixes from subdirectory path components, so_add_section_sidebar'ssorted(subdir_groups_dict.keys())sorted the stripped names —applied-modelsbeforefoundations— discarding the author's ordering. The source file list is already sorted with prefixes intact, so the grouping dict's insertion order is the intended order; iterating the dict directly preserves it.Related GitHub Issues and PRs
Checklist
Closes #295
test_add_section_sidebar_preserves_subdir_orderwas added beside the existing sidebar tests intests/test_great_docs.py; it fails onmainand passes with this change. This change was prepared with AI assistance; the regression test was run locally and fails without the fix.