Skip to content

Commit 9762bbf

Browse files
committed
Use JSON-LD link if found in HTML template
1 parent f794d67 commit 9762bbf

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pygeoapi/templates/_base.html

+9-5
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@
6767
<a href="{{ config['server']['url'] }}">{% trans %}Home{% endtrans %}</a>
6868
{% endblock %}
6969
<span style="float: inline-end">
70-
{% set links_found = namespace(json=0, jsonld=0) %}
70+
{% set links_found = namespace(json='', jsonld='') %}
7171

7272
{% for link in data['links'] %}
7373
{% if link['rel'] == 'alternate' and link['type'] and link['type'] in ['application/json', 'application/geo+json', 'application/prs.coverage+json'] %}
74-
{% set links_found.json = 1 %}
74+
{% set links_found.json = link.href | string | safe %}
7575
<a href="{{ link['href'] }}">{% trans %}json{% endtrans %}</a>
7676
{% elif link['rel'] == 'alternate' and link['type'] and link['type'] == 'application/ld+json' %}
77-
{% set links_found.jsonld = 1 %}
77+
{% set links_found.jsonld = link.href | string | safe %}
7878
<a href="{{ link['href'] }}">{% trans %}jsonld{% endtrans %}</a>
7979
{% endif %}
8080
{% endfor %}
8181

82-
{% if links_found.json == 0 %}
82+
{% if links_found.json == '' %}
8383
<a href="?f=json">{% trans %}json{% endtrans %}</a>
8484
{% endif %}
85-
{% if links_found.jsonld == 0 %}
85+
{% if links_found.jsonld == '' %}
8686
<a href="?f=jsonld">{% trans %}jsonld{% endtrans %}</a>
8787
{% endif %}
8888

@@ -114,7 +114,11 @@
114114
<script>
115115
// Requests and embeds JSON-LD representation of current page
116116
var xhr = new XMLHttpRequest();
117+
{% if links_found.jsonld == '' -%}
117118
var path = window.location.protocol + "//" + window.location.host + window.location.pathname + "?f=jsonld";
119+
{%- else -%}
120+
var path = "{{ links_found.jsonld }}";
121+
{%- endif %}
118122
xhr.open('GET', path);
119123
xhr.onload = function() {
120124
if (xhr.status === 200) {

0 commit comments

Comments
 (0)