11"""titiler app."""
22
33import logging
4- import re
54
65import jinja2
76import rasterio
@@ -232,6 +231,25 @@ def application_health_check():
232231@app .get ("/" , response_class = HTMLResponse , include_in_schema = False )
233232def landing (request : Request ):
234233 """TiTiler landing page."""
234+ urlpath = request .url .path
235+ if root_path := request .scope .get ("root_path" ):
236+ urlpath = urlpath .removeprefix (root_path )
237+
238+ crumbs = []
239+ baseurl = str (request .base_url ).rstrip ("/" )
240+
241+ crumbpath = str (baseurl )
242+ if urlpath == "/" :
243+ urlpath = ""
244+
245+ for crumb in urlpath .split ("/" ):
246+ crumbpath = crumbpath .rstrip ("/" )
247+ part = crumb
248+ if part is None or part == "" :
249+ part = "Home"
250+ crumbpath += f"/{ crumb } "
251+ crumbs .append ({"url" : crumbpath .rstrip ("/" ), "part" : part .capitalize ()})
252+
235253 data = {
236254 "title" : "titiler" ,
237255 "links" : [
@@ -268,21 +286,6 @@ def landing(request: Request):
268286 ],
269287 }
270288
271- urlpath = request .url .path
272- if root_path := request .app .root_path :
273- urlpath = re .sub (r"^" + root_path , "" , urlpath )
274- crumbs = []
275- baseurl = str (request .base_url ).rstrip ("/" )
276-
277- crumbpath = str (baseurl )
278- for crumb in urlpath .split ("/" ):
279- crumbpath = crumbpath .rstrip ("/" )
280- part = crumb
281- if part is None or part == "" :
282- part = "Home"
283- crumbpath += f"/{ crumb } "
284- crumbs .append ({"url" : crumbpath .rstrip ("/" ), "part" : part .capitalize ()})
285-
286289 return templates .TemplateResponse (
287290 "index.html" ,
288291 {
@@ -294,9 +297,5 @@ def landing(request: Request):
294297 "title" : "TiTiler" ,
295298 },
296299 "crumbs" : crumbs ,
297- "url" : str (request .url ),
298- "baseurl" : baseurl ,
299- "urlpath" : str (request .url .path ),
300- "urlparams" : str (request .url .query ),
301300 },
302301 )
0 commit comments