Skip to content

Commit

Permalink
Merge pull request #195 from GSA/4360_jsonld-metatags
Browse files Browse the repository at this point in the history
4360 `json+ld` improvements
  • Loading branch information
jbrown-xentity authored May 31, 2024
2 parents 05c65eb + 194dfea commit b379b18
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
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

0 comments on commit b379b18

Please sign in to comment.