Skip to content

fix: preserve source order for sidebar subsections - #299

Merged
rich-iannone merged 1 commit into
posit-dev:mainfrom
Sanjays2402:fix/sidebar-subdir-source-order
Aug 2, 2026
Merged

fix: preserve source order for sidebar subsections#299
rich-iannone merged 1 commit into
posit-dev:mainfrom
Sanjays2402:fix/sidebar-subdir-source-order

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Summary

Custom sections with numeric-prefixed subdirectories rendered their sidebar subsections alphabetically instead of in 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 — 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_order was added beside the existing sidebar tests in tests/test_great_docs.py; it fails on main and passes with this change. This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

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.

@rich-iannone rich-iannone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!!

@rich-iannone
rich-iannone merged commit 27b0d89 into posit-dev:main Aug 2, 2026
8 checks passed
@rich-iannone

Copy link
Copy Markdown
Member

Thanks for this PR: really appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom section sidebar sorts subdirectories alphabetically after prefix stripping, breaking numeric order

2 participants