Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON-LD link if found for HTML injection #1954

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pygeoapi/templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@
<a href="{{ config['server']['url'] }}">{% trans %}Home{% endtrans %}</a>
{% endblock %}
<span style="float: inline-end">
{% set links_found = namespace(json=0, jsonld=0) %}
{% set links_found = namespace(json='', jsonld='') %}

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

{% if links_found.json == 0 %}
{% if links_found.json == '' %}
<a href="?f=json">{% trans %}json{% endtrans %}</a>
{% endif %}
{% if links_found.jsonld == 0 %}
{% if links_found.jsonld == '' %}
<a href="?f=jsonld">{% trans %}jsonld{% endtrans %}</a>
{% endif %}

Expand Down Expand Up @@ -114,7 +114,11 @@
<script>
// Requests and embeds JSON-LD representation of current page
var xhr = new XMLHttpRequest();
{% if links_found.jsonld == '' -%}
var path = window.location.protocol + "//" + window.location.host + window.location.pathname + "?f=jsonld";
{%- else -%}
var path = "{{ links_found.jsonld }}";
{%- endif %}
xhr.open('GET', path);
xhr.onload = function() {
if (xhr.status === 200) {
Expand Down