11# Python Standard Library Imports
22import copy
3+ import re
34
45# Third Party (PyPI) Imports
56from flask import (
1819 PHABRICATOR_INSTANCE_BASE_URL ,
1920)
2021from phablytics .web .constants import (
21- BREADCRUMBS ,
22+ BREADCRUMB_OVERRIDES ,
2223 NAV_LINKS ,
2324 SITE_NAME ,
2425)
2526
2627
28+ REPORT_PATH_REGEX = re .compile (r'^/reports/[^/]+$' )
29+
30+
2731def custom_render_template (template_name , context_data = None ):
2832 if context_data is None :
2933 context_data = {}
@@ -79,6 +83,11 @@ def _format_nav_link(nav_link):
7983 return nav_links
8084
8185
86+ def is_report_name_path (path ):
87+ result = REPORT_PATH_REGEX .match (path ) is not None
88+ return result
89+
90+
8291def get_breadcrumbs ():
8392 breadcrumbs = []
8493
@@ -91,8 +100,26 @@ def get_breadcrumbs():
91100
92101 for i , path_part in enumerate (path_parts ):
93102 path = '/' .join (path_parts [:i + 1 ]) or '/'
103+ path_suffix = '/' .join (path_parts [i + 1 :])
94104 is_active = i + 1 == len (path_parts )
95- name = BREADCRUMBS .get (path , path_part .title ())
105+
106+ default_breadcrumb_name = (
107+ path_part
108+ if (
109+ # leave alone if any conditions are satisfied
110+ is_report_name_path (path )
111+ )
112+ # else format breadcrumb as Titlecase
113+ else path_part .title ()
114+ )
115+
116+ name = BREADCRUMB_OVERRIDES .get (
117+ path , # get breadcrumb by full path
118+ BREADCRUMB_OVERRIDES .get (
119+ path_suffix , # get breadcrumb by path_suffix
120+ default_breadcrumb_name # fallback: generated breadcrumb based on path
121+ )
122+ )
96123 breadcrumb = {
97124 'name' : name ,
98125 'url' : path ,
0 commit comments