exceptional-case tag sorting to treat æ ligature as "ae"
authorM. Taylor Saotome-Westlake <[email protected]>
Sun, 19 Apr 2020 23:01:46 +0000 (16:01 -0700)
committerM. Taylor Saotome-Westlake <[email protected]>
Sun, 19 Apr 2020 23:01:46 +0000 (16:01 -0700)
I would hope that Unicode has standardized support for this need?—but
if I couldn't quickly find it, this will do.

plugins/tag_cloud.py

index 775977e..6672e2b 100644 (file)
@@ -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':