From: M. Taylor Saotome-Westlake Date: Sun, 19 Apr 2020 23:01:46 +0000 (-0700) Subject: exceptional-case tag sorting to treat æ ligature as "ae" X-Git-Url: http://unremediatedgender.space/source?a=commitdiff_plain;h=466a818df55a62185ac4f48d7908907bcc8e3510;p=Ultimately_Untrue_Thought.git exceptional-case tag sorting to treat æ ligature as "ae" I would hope that Unicode has standardized support for this need?—but if I couldn't quickly find it, this will do. --- diff --git a/plugins/tag_cloud.py b/plugins/tag_cloud.py index 775977e..6672e2b 100644 --- a/plugins/tag_cloud.py +++ b/plugins/tag_cloud.py @@ -36,6 +36,15 @@ def init_default_config(pelican): set_default_settings(pelican.settings) +def alphabetic_sort_key(element): + tag = element[0].name + if tag[0] == "æ": # exceptional case + return "ae"+tag[1:] + # `.lower()` to avoid putting all uppercase tags lexicographically + # before lowercase tags —ZMD + return tag.lower() + + def generate_tag_cloud(generator): tag_cloud = defaultdict(int) for article in generator.articles: @@ -69,9 +78,7 @@ def generate_tag_cloud(generator): sorting = generator.settings.get('TAG_CLOUD_SORTING') if sorting == 'alphabetically': - # `.lower()` to avoid putting all uppercase tags lexicographically - # before lowercase tags —ZMD - tag_cloud.sort(key=lambda elem: elem[0].name.lower()) + tag_cloud.sort(key=alphabetic_sort_key) elif sorting == 'alphabetically-rev': tag_cloud.sort(key=lambda elem: elem[0].name, reverse=True) elif sorting == 'size':