Open evanwill opened 4 years ago
example:
Aerial has county
and region
both schema_map to contentLocation
.
Which results in repeating contentLocation
key, like:
{
"@context": "http://schema.org",
"@type": "CreativeWork",
"dateCreated": "1934",
"description": "Black and white 1934 vertical air photo taken from aircraft, by the Washington National Guard.",
"contentLocation": "Clearwater County (Idaho)",
"contentLocation": "Sheep Mountain",
"encodingFormat": "image/jpeg",
"isPartOf": "Idaho Historical Aerial Photographs",
"image": "https://digital.lib.uidaho.edu/digital/iiif/uiiap/256/full/max/0/default.jpg",
"thumbnailUrl": "https://digital.lib.uidaho.edu/utils/getthumbnail/collection/uiiap/id/256",
"url": "https://www.lib.uidaho.edu/digital/aerial/items/aerial256.html"
}
Should look like:
{
"@context": "http://schema.org",
"@type": "CreativeWork",
"dateCreated": "1934",
"description": "Black and white 1934 vertical air photo taken from aircraft, by the Washington National Guard.",
"contentLocation": ["Clearwater County (Idaho)","Sheep Mountain"],
"encodingFormat": "image/jpeg",
"isPartOf": "Idaho Historical Aerial Photographs",
"image": "https://digital.lib.uidaho.edu/digital/iiif/uiiap/256/full/max/0/default.jpg",
"thumbnailUrl": "https://digital.lib.uidaho.edu/utils/getthumbnail/collection/uiiap/id/256",
"url": "https://www.lib.uidaho.edu/digital/aerial/items/aerial256.html"
}
Not impossible, but involves adding a ton of Liquid to catch repeating schema_map content.
example insane Liquid:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "CreativeWork",
{%- assign schema = site.data.config-metadata | where_exp: 'item', 'item.schema_map != nil' | group_by: "schema_map" -%}
{%- assign schema-fields = schema | map: 'name' | uniq -%}
{%- for f in schema-fields -%}
{%- assign fields = schema | where: 'name',f | map: 'items' | map: 'field' -%}
{% if fields.size > 1 %}
{% capture values %}{% for t in fields %}{% if page[t] %}{{ page[t] }}||{% endif %}{% endfor %}{%- endcapture -%}
{%- assign values = values | split: "||" | compact -%}
{% if values != empty %}"{{ f }}": {{ values | jsonify }},{% endif %}
{%- else -%}
{% if page[fields.first] %}"{{ f }}": {{ page[fields.first] | jsonify }},{%- endif -%}
{%- endif -%}
{% endfor %}
"isPartOf": {{ site.title | jsonify }},
{% if page.format contains 'image' %}"image": "{% include image/original.html %}",{% endif %}
"thumbnailUrl": "{% include image/thumb.html %}",
"url": {{ page.url | absolute_url | jsonify }}
}
</script>
if you repeat a key in schema_map, it will just add another instance of that key, which is an error, since keys need to be unique. Should try to combine fields with same schema_map into one key with array as value, since sometimes it makes sense to have multiple fields mapped to same key. (but the liquid to do this gets really convoluted to support this edge case, so need to think it through.)
important because if keys repeat, google considers the markup broken and makes ineligible for rich results.