Skip to content

Commit

Permalink
Alphabetize documentation sidenav elements (#5080)
Browse files Browse the repository at this point in the history
* Fix ordering of sidenav elements to make sure they're alphabetical
* programmatically sort sidenav elements by configuration in side-navigation.yaml
* remove sidenav alphabetize recursive support (not needed currently)
* prettier on side-navigation.yaml
* simplify sidenav yaml structure
  • Loading branch information
jmuzina committed May 7, 2024
1 parent 51d7873 commit ff6325f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions side-navigation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- title: Migrating to v4
url: /docs/migration-guide-to-v4
- heading: Base elements
ordering: alphabetical
subheadings:
- title: Code
url: /docs/base/code
Expand All @@ -26,7 +27,9 @@
url: /docs/base/typography
- title: Paper background
url: /docs/base/paper

- heading: Components
ordering: alphabetical
subheadings:
- title: Accordion
url: /docs/patterns/accordion
Expand Down Expand Up @@ -109,6 +112,7 @@
- title: Tooltips
url: /docs/patterns/tooltips
- heading: Utilities
ordering: alphabetical
subheadings:
- title: Align
url: /docs/utilities/align
Expand Down Expand Up @@ -153,6 +157,7 @@
- title: Vertically center
url: /docs/utilities/vertically-center
- heading: Layouts
ordering: alphabetical
subheadings:
- title: Application
url: /docs/layouts/application
Expand All @@ -167,6 +172,7 @@
- title: Sticky footer
url: /docs/layouts/sticky-footer
- heading: Settings
ordering: alphabetical
subheadings:
- title: Animations
url: /docs/settings/animation-settings
Expand All @@ -187,6 +193,7 @@
- title: Table layout
url: /docs/settings/table-layout
- heading: Resources
ordering: alphabetical
subheadings:
- title: Component examples
url: /docs/examples
Expand Down
28 changes: 28 additions & 0 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,39 @@

# Read side-navigation.yaml
with open("side-navigation.yaml") as side_navigation_file:
# maps values of `side_navigation_file.subheadings.ordering` to their implementations
supported_orderings = {
"alphabetical": lambda subheadings, by_attribute: sorted(subheadings, key=lambda subheading: subheading[by_attribute])
}

SIDE_NAVIGATION = yaml.load(
side_navigation_file.read(),
Loader=yaml.FullLoader,
)

def alphabetize_heading_items(heading, by_attribute="title"):
"""
Alphabetizes the sub-heading items contained by the heading
:param heading:
:param by_attribute: Key name of the attribute within each subheading item to use for alphabetization
:return: Altered `heading` with its subheading items alphabetized
"""
subheadings = None
subheadings_ordering_identifier = None
subheadings_ordering_fn = None
try:
subheadings_ordering_identifier = heading["ordering"]
subheadings_ordering_fn = supported_orderings[subheadings_ordering_identifier]
except KeyError:
return heading

heading["subheadings"] = subheadings_ordering_fn(heading["subheadings"], by_attribute)

return heading

for heading in SIDE_NAVIGATION:
heading = alphabetize_heading_items(heading)


app = FlaskBase(
__name__,
Expand Down

0 comments on commit ff6325f

Please sign in to comment.