Skip to content

Commit cb713c3

Browse files
committed
Use JSON-LD link if found in HTML template
1 parent 219e4cc commit cb713c3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pygeoapi/templates/_base.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@
8080
<a href="{{ config['server']['url'] }}">{% trans %}Home{% endtrans %}</a>
8181
{% endblock %}
8282
<span style="float: inline-end">
83-
{% set links_found = namespace(json=0, jsonld=0) %}
83+
{% set links_found = namespace(json='', jsonld='') %}
8484

8585
{% for link in data['links'] %}
8686
{% if link['rel'] == 'alternate' and link['type'] and link['type'] in ['application/json', 'application/geo+json', 'application/prs.coverage+json'] %}
87-
{% set links_found.json = 1 %}
87+
{% set links_found.json = link.href | string | safe %}
8888
<a href="{{ link['href'] }}">{% trans %}json{% endtrans %}</a>
8989
{% elif link['rel'] == 'alternate' and link['type'] and link['type'] == 'application/ld+json' %}
90-
{% set links_found.jsonld = 1 %}
90+
{% set links_found.jsonld = link.href | string | safe %}
9191
<a href="{{ link['href'] }}">{% trans %}jsonld{% endtrans %}</a>
9292
{% endif %}
9393
{% endfor %}
9494

95-
{% if links_found.json == 0 %}
95+
{% if links_found.json == '' %}
9696
<a href="?f=json">{% trans %}json{% endtrans %}</a>
9797
{% endif %}
98-
{% if links_found.jsonld == 0 %}
98+
{% if links_found.jsonld == '' %}
9999
<a href="?f=jsonld">{% trans %}jsonld{% endtrans %}</a>
100100
{% endif %}
101101

@@ -127,7 +127,11 @@
127127
<script>
128128
// Requests and embeds JSON-LD representation of current page
129129
var xhr = new XMLHttpRequest();
130+
{% if links_found.jsonld == '' -%}
130131
var path = window.location.protocol + "//" + window.location.host + window.location.pathname + "?f=jsonld";
132+
{%- else -%}
133+
var path = "{{ links_found.jsonld }}";
134+
{%- endif %}
131135
xhr.open('GET', path);
132136
xhr.onload = function() {
133137
if (xhr.status === 200) {

0 commit comments

Comments
 (0)