diff options
author | 2022-02-01 02:38:48 +0100 | |
---|---|---|
committer | 2022-02-01 02:38:48 +0100 | |
commit | 1f41d185414d5d3a7ce056828541d09a860037ce (patch) | |
tree | 464c09804e05845422d4c638bba32bb2a37813f9 /pydis_site/apps/resources | |
parent | Fix bug where transition wouldn't work on first collapse. (diff) |
Sort resources alphabetically, disregarding 'the'.
Diffstat (limited to 'pydis_site/apps/resources')
-rw-r--r-- | pydis_site/apps/resources/views/resources.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py index 55d104bd..1895f12a 100644 --- a/pydis_site/apps/resources/views/resources.py +++ b/pydis_site/apps/resources/views/resources.py @@ -17,6 +17,15 @@ RESOURCES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "resources", "res class ResourceView(View): """Our curated list of good learning resources.""" + @staticmethod + def _sort_key_disregard_the(tuple_): + """Sort a tuple by its key alphabetically, disregarding 'the' as a prefix.""" + name, resource = tuple_ + name = name.casefold() + if name.startswith("the ") or name.startswith("the_"): + return name[4:] + return name + def __init__(self, *args, **kwargs): """Set up all the resources.""" super().__init__(*args, **kwargs) @@ -28,7 +37,7 @@ class ResourceView(View): } # Sort the resources alphabetically - self.resources = dict(sorted(self.resources.items())) + self.resources = dict(sorted(self.resources.items(), key=self._sort_key_disregard_the)) # Parse out all current tags resource_tags = { |