@@ -115,17 +115,28 @@ def create_html_response(
115
115
data : Any ,
116
116
templates : Jinja2Templates ,
117
117
template_name : str ,
118
+ title : Optional [str ] = None ,
118
119
router_prefix : Optional [str ] = None ,
120
+ ** kwargs : Any ,
119
121
) -> _TemplateResponse :
120
122
"""Create Template response."""
121
123
urlpath = request .url .path
122
124
if root_path := request .app .root_path :
123
125
urlpath = re .sub (r"^" + root_path , "" , urlpath )
124
126
127
+ if router_prefix :
128
+ urlpath = re .sub (r"^" + router_prefix , "" , urlpath )
129
+
125
130
crumbs = []
126
131
baseurl = str (request .base_url ).rstrip ("/" )
127
132
133
+ if router_prefix :
134
+ baseurl += router_prefix
135
+
128
136
crumbpath = str (baseurl )
137
+ if urlpath == "/" :
138
+ urlpath = ""
139
+
129
140
for crumb in urlpath .split ("/" ):
130
141
crumbpath = crumbpath .rstrip ("/" )
131
142
part = crumb
@@ -134,9 +145,6 @@ def create_html_response(
134
145
crumbpath += f"/{ crumb } "
135
146
crumbs .append ({"url" : crumbpath .rstrip ("/" ), "part" : part .capitalize ()})
136
147
137
- if router_prefix :
138
- baseurl += router_prefix
139
-
140
148
return templates .TemplateResponse (
141
149
request ,
142
150
name = f"{ template_name } .html" ,
@@ -145,13 +153,12 @@ def create_html_response(
145
153
"template" : {
146
154
"api_root" : baseurl ,
147
155
"params" : request .query_params ,
148
- "title" : "" ,
156
+ "title" : title or template_name ,
149
157
},
150
158
"crumbs" : crumbs ,
151
- "url" : str (request .url ),
152
- "baseurl" : baseurl ,
153
- "urlpath" : str (request .url .path ),
154
- "urlparams" : str (request .url .query ),
159
+ "url" : baseurl + urlpath ,
160
+ "params" : str (request .url .query ),
161
+ ** kwargs ,
155
162
},
156
163
)
157
164
@@ -208,13 +215,17 @@ def _create_html_response(
208
215
request : Request ,
209
216
data : Any ,
210
217
template_name : str ,
218
+ title : Optional [str ] = None ,
219
+ ** kwargs : Any ,
211
220
) -> _TemplateResponse :
212
221
return create_html_response (
213
222
request ,
214
223
data ,
215
224
templates = self .templates ,
216
225
template_name = template_name ,
226
+ title = title ,
217
227
router_prefix = self .router_prefix ,
228
+ ** kwargs ,
218
229
)
219
230
220
231
@abc .abstractmethod
@@ -326,6 +337,7 @@ def landing(
326
337
request ,
327
338
data .model_dump (exclude_none = True , mode = "json" ),
328
339
template_name = "landing" ,
340
+ title = self .title ,
329
341
)
330
342
331
343
return data
@@ -520,6 +532,7 @@ def collections(
520
532
request ,
521
533
data .model_dump (exclude_none = True , mode = "json" ),
522
534
template_name = "collections" ,
535
+ title = "Collections list" ,
523
536
)
524
537
525
538
return data
@@ -607,6 +620,7 @@ def collection(
607
620
request ,
608
621
data .model_dump (exclude_none = True , mode = "json" ),
609
622
template_name = "collection" ,
623
+ title = f"{ collection .id } collection" ,
610
624
)
611
625
612
626
return data
@@ -652,6 +666,7 @@ def queryables(
652
666
request ,
653
667
data .model_dump (exclude_none = True , mode = "json" ),
654
668
template_name = "queryables" ,
669
+ title = f"{ collection .id } queryables" ,
655
670
)
656
671
657
672
return data
@@ -908,6 +923,7 @@ async def items( # noqa: C901
908
923
request ,
909
924
orjson .loads (orjsonDumps (data ).decode ()),
910
925
template_name = "items" ,
926
+ title = f"{ collection .id } items" ,
911
927
)
912
928
913
929
# GeoJSONSeq Response
@@ -1074,6 +1090,7 @@ async def item(
1074
1090
request ,
1075
1091
orjson .loads (orjsonDumps (data ).decode ()),
1076
1092
template_name = "item" ,
1093
+ title = f"{ collection .id } /{ itemId } item" ,
1077
1094
)
1078
1095
1079
1096
# Default to GeoJSON Response
@@ -1212,6 +1229,7 @@ async def tilematrixsets(
1212
1229
request ,
1213
1230
data .model_dump (exclude_none = True , mode = "json" ),
1214
1231
template_name = "tilematrixsets" ,
1232
+ title = "TileMatrixSets list" ,
1215
1233
)
1216
1234
1217
1235
return data
@@ -1254,6 +1272,7 @@ async def tilematrixset(
1254
1272
"bbox" : tms .bbox ,
1255
1273
},
1256
1274
template_name = "tilematrixset" ,
1275
+ title = f"{ tileMatrixSetId } TileMatrixSet" ,
1257
1276
)
1258
1277
1259
1278
return tms
@@ -1346,6 +1365,7 @@ async def collection_tileset_list(
1346
1365
request ,
1347
1366
data .model_dump (exclude_none = True , mode = "json" ),
1348
1367
template_name = "tilesets" ,
1368
+ title = f"{ collection .id } tilesets" ,
1349
1369
)
1350
1370
1351
1371
return data
@@ -1460,6 +1480,7 @@ async def collection_tileset(
1460
1480
request ,
1461
1481
data .model_dump (exclude_none = True , mode = "json" ),
1462
1482
template_name = "tileset" ,
1483
+ title = f"{ collection .id } { tileMatrixSetId } tileset" ,
1463
1484
)
1464
1485
1465
1486
return data
0 commit comments