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

4360 json+ld improvements #195

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions ckanext/datagovtheme/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% endblock %}
{% block open_graph_previews %}
{% include '/snippets/link_preview.html' %}
{% include '/snippets/jsonld.html' %}
{% endblock %}
{% endblock %}

Expand Down
63 changes: 63 additions & 0 deletions ckanext/datagovtheme/templates/snippets/jsonld.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

{% block jsonld %}
{% set pkg = c.pkg_dict %}

{% if pkg %}
{% set dataset = pkg.title or pkg.name or "Data.gov Dataset" %}
{% set organization = pkg.organization.title or pkg.organization.name or "Data.gov" %}
{% set notes = h.markdown_extract(pkg.notes, 180) or "The Home of the U.S. Government's Open Data" %}


<script type="application/ld+json" class="jsonld-website">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "https://data.gov",
"name": "Data.gov",
"potentialAction": {
"@type": "SearchAction",
"target": "https://catalog.data.gov/dataset?q={search_term_string}&sort=views_recent+desc&ext_location=&ext_bbox=&ext_prev_extent=",
"query-input": "required name=search_term_string"
}
}
</script>
<script type="application/ld+json" class="jsonld-org">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://data.gov",
"name": "Data.gov",
"slogan": "The Home of the U.S. Government's Open Data",
"contactPoint": {
"@type": "ContactPoint",
"url": "https://data.gov/contact/",
"contactType": "Datagov Support"
}
}
</script>
<script type="application/ld+json" class="jsonld-dataset">
{
"@type": "schema:Dataset",
"name": "{{ organization }} - {{ dataset }}"",
"description": "{{ notes }}",
"keywords": [
{% if pkg.tags %}
{% for tag in pkg.tags %}
"{{ tag.name }}"{% if not loop.last %},{% endif %}
{% endfor %}
{% elif pkg_dict['tags'] %}
{% for tag in pkg_dict['tags'] %}
"{{ tag['name'] }}"{% if not loop.last %},{% endif %}
{% endfor %}
{% endif %}
],
"publisher": {
"type": "Organization",
"contactPoint": { "type": "PostalAddress" }
},
"distribution": []
}
</script>

{% endif %}
{% endblock %}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="ckanext-datagovtheme",
version="0.2.20",
version="0.2.21",
description="CKAN Extension to manage data.gov theme",
long_description=long_description,
classifiers=[
Expand Down
Loading