]> git.0d.be Git - panikweb.git/commitdiff
rewrite main nav active section highlighting
authorFrédéric Péters <fpeters@0d.be>
Sat, 21 Nov 2020 21:13:05 +0000 (22:13 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sat, 21 Nov 2020 21:13:05 +0000 (22:13 +0100)
panikweb/paniktags/templatetags/paniktags.py

index 0cea84184530e07037109dd6c045e9c8b2ac13af..2817163001c4501e0a1d2ba9892159e6d174e1f1 100644 (file)
@@ -134,23 +134,30 @@ def metanav(context):
     except KeyError:
         # a context without 'requests' may happen when rendering error pages
         request_path = 'xxx'
-    section = 'About'
+    paths = {
+        '/actus/': 'News',
+        '/sons/': 'Listen',
+        '/podcasts/': 'Listen',
+        '/topiks/': 'Topiks',
+        '/emissions': 'Emissions',
+        '/grille': 'Emissions',
+        '/programme/': 'Emissions',
+        '/recherche/': 'Search',
+        '/la-radio/': 'About',
+    }
+    section = ''
     if request_path == '/':
         section = 'Home'
-    elif request_path.startswith('/actus/'):
-        section = 'News'
-    elif request_path.startswith('/sons/'):
-        section = 'Listen'
-    elif request_path.startswith('/topiks'):
-        section = 'Topiks'
-    elif request_path.startswith('/emissions') or request_path == '/grille' or request_path == '/programme/':
-        section = 'Emissions'
-    elif request_path == '/recherche/':
-        section = 'Search'
+    else:
+        for path, section_name in paths.items():
+            if request_path.startswith(path):
+                section = section_name
+                break
     return {
         'LANGUAGE_CODE': context.get('LANGUAGE_CODE'),
         'sectionName': section,
-        }
+    }
+
 
 @register.inclusion_tag('includes/week.html')
 def weekview(year=None, week=None):