Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphabetize documentation sidenav elements #5080

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -107,6 +110,7 @@
- title: Tooltips
url: /docs/patterns/tooltips
- heading: Utilities
ordering: alphabetical
subheadings:
- title: Align
url: /docs/utilities/align
Expand Down Expand Up @@ -151,6 +155,7 @@
- title: Vertically center
url: /docs/utilities/vertically-center
- heading: Layouts
ordering: alphabetical
subheadings:
- title: Application
url: /docs/layouts/application
Expand All @@ -165,6 +170,7 @@
- title: Sticky footer
url: /docs/layouts/sticky-footer
- heading: Settings
ordering: alphabetical
subheadings:
- title: Animations
url: /docs/settings/animation-settings
Expand All @@ -185,6 +191,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