9
9
class OGCAPIFeaturesExporter :
10
10
11
11
@staticmethod
12
- def generateOGCAPIFeaturesPages (outpath ,deploypath , featurecollectionspaths , prefixnamespace , ogcapi , mergeJSON ):
12
+ def generateOGCAPIFeaturesPages (outpath ,deploypath , featurecollectionspaths , prefixnamespace , ogcapi , mergeJSON , contentnegotiation = False ):
13
13
apihtml = "<!DOCTYPE html><html lang=\" en\" ><head><meta charset=\" utf-8\" /><meta name=\" viewport\" content=\" width=device-width, initial-scale=1\" /><metaname=\" description\" content=\" SwaggerUI\" /><title>SwaggerUI</title><link rel=\" stylesheet\" href=\" https://unpkg.com/swagger-ui-dist/swagger-ui.css\" /></head><body><div id=\" swagger-ui\" ></div><script src=\" https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script><script>const swaggerUrl = \" " + str (
14
14
deploypath ) + "/api/index.json\" ; const apiUrl = \" " + str (
15
15
deploypath ) + "/\" ; window.onload = () => {let swaggerJson = fetch(swaggerUrl).then(r => r.json().then(j => {j.servers[0].url = apiUrl; window.ui = SwaggerUIBundle({spec: j,dom_id: '#swagger-ui'});}));};</script></body></html>"
16
+ collectionhtmlname = "indexc.html"
17
+ if contentnegotiation :
18
+ collectionhtmlname = "index.html"
16
19
apijson = {"openapi" : "3.0.1" , "info" : {"title" : str (deploypath ) + " Feature Collections" ,
17
20
"description" : "Feature Collections of " + str (deploypath )},
18
21
"servers" : [{"url" : str (deploypath )}], "paths" : {}}
@@ -95,7 +98,7 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
95
98
"type" : "application/json" ,
96
99
"title" : "Supported Feature Collections as JSON"
97
100
}, {
98
- "href" : str (deploypath ) + "/collections/indexc.html" ,
101
+ "href" : str (deploypath ) + "/collections/" + collectionhtmlname ,
99
102
"rel" : "data" ,
100
103
"type" : "text/html" ,
101
104
"title" : "Supported Feature Collections as HTML"
@@ -179,7 +182,7 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
179
182
currentcollection ["links" ] = [
180
183
{"href" : opwebcoll + "/items/index.json" , "rel" : "items" , "type" : "application/json" ,
181
184
"title" : "Collection as JSON" },
182
- {"href" : opwebcoll + "/items/indexc.html" , "rel" : "items" , "type" : "text/html" ,
185
+ {"href" : opwebcoll + "/items/" + collectionhtmlname , "rel" : "items" , "type" : "text/html" ,
183
186
"title" : "Collection as HTML" },
184
187
{"href" : opwebcoll + "/items/index.ttl" , "rel" : "collection" , "type" : "text/ttl" ,
185
188
"title" : "Collection as TTL" }]
@@ -202,15 +205,15 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
202
205
coll .replace (outpath , "" ).replace ("index.geojson" , "" ).replace (".geojson" , "" )[1 :]),
203
206
"parameters" : [], "responses" : {"default" : {"description" : "default response" , "content" : {
204
207
"application/json" : {"schema" : {"$ref" : "#/components/schemas/Collections" },"example" : None }}}}}}
205
- curcollrow = "<tr><td><a href=\" " + opweb .replace (".geojson" , "" ) + "/items/indexc.html \" >" + str (
208
+ curcollrow = "<tr><td><a href=\" " + opweb .replace (".geojson" , "" ) + "/items/" + collectionhtmlname + " \" >" + str (
206
209
featurecollectionspaths [coll ]["name" ]) + "</a></td><td>" + str (len (curcoll ["features" ]))+ "</td><td><a href=\" " + opweb .replace (".geojson" ,
207
- "" ) + "/items/indexc.html \" >[Collection as HTML]</a> <a href=\" " + opweb .replace (
210
+ "" ) + "/items/" + collectionhtmlname + " \" >[Collection as HTML]</a> <a href=\" " + opweb .replace (
208
211
".geojson" , "" ) + "/items/\" >[Collection as JSON]</a> <a href=\" " + opweb .replace (".geojson" ,
209
212
"" ) + "/items/index.ttl\" >[Collection as TTL]</a></td></tr>"
210
213
f = open (op + "index.json" , "w" , encoding = "utf-8" )
211
214
f .write (json .dumps (currentcollection ))
212
215
f .close ()
213
- f = open (op + "indexc.html" , "w" , encoding = "utf-8" )
216
+ f = open (op + collectionhtmlname , "w" , encoding = "utf-8" )
214
217
f .write ("<html><head><meta name=\" viewport\" content=\" width=device-width, initial-scale=1\" /></head><body><h1>" + featurecollectionspaths [coll ][
215
218
"name" ] + "</h1><table><thead><tr><th>Collection</th><th>Links</th></tr></thead><tbody>" + str (
216
219
curcollrow ) + "</tbody></table></html>" )
@@ -241,8 +244,8 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
241
244
coll .replace ("//" , "/" ).replace ("index.geojson" , "index.html" ).replace (
242
245
"nonns_" + featurecollectionspaths [coll ]["id" ] + ".geojson" ,
243
246
"nonns_" + featurecollectionspaths [coll ]["id" ] + ".html" ),
244
- str (op + "/items/indexc.html" ).replace ("//" , "/" ), outpath )
245
- f = open (str (op + "/items/indexc.html" ), "w" )
247
+ str (op + "/items/" + collectionhtmlname ).replace ("//" , "/" ), outpath )
248
+ f = open (str (op + "/items/" + collectionhtmlname ), "w" )
246
249
if "nonns" in collid :
247
250
f .write (
248
251
"<html><head><meta http-equiv=\" refresh\" content=\" 0; url=" + deploypath + "/" + collid + ".html" + "\" /></head></html>" )
@@ -361,7 +364,7 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
361
364
f = open (outpath + "/api/api.html" , "w" , encoding = "utf-8" )
362
365
f .write (apihtml )
363
366
f .close ()
364
- f = open (outpath + "/collections/indexc.html" , "w" , encoding = "utf-8" )
367
+ f = open (outpath + "/collections/" + collectionhtmlname , "w" , encoding = "utf-8" )
365
368
f .write (collectionshtml .replace ("{{collectiontable}}" , collectiontable ))
366
369
f .close ()
367
370
f = open (outpath + "/collections/index.json" , "w" , encoding = "utf-8" )
0 commit comments