Skip to content

Instantly share code, notes, and snippets.

@illvart
Created May 9, 2019 17:21
Show Gist options
  • Save illvart/ab4e2a51029fb470bac8b839bbd2ef81 to your computer and use it in GitHub Desktop.
Save illvart/ab4e2a51029fb470bac8b839bbd2ef81 to your computer and use it in GitHub Desktop.
Meta schema JSON on Eleventy by nunjucks include, set, filter, custom tags.
<script type="application/ld+json">
{% minifyJson %}
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "{{ metadata.url }}",
"potentialAction": {
"@type": "SearchAction",
"target": "{{ metadata.url }}/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
{% endMinifyJson %}
</script>
<script type="application/ld+json">
{% minifyJson %}
{
"@context": "http://schema.org",
"@type": "Person",
"name": "{{ metadata.title }}",
"url": "{{ metadata.url }}",
"sameAs": [
"{{ metadata.author.social.facebook }}",
"{{ metadata.author.social.twitter }}",
"{{ metadata.author.social.github }}"
]
}
{% endMinifyJson %}
</script>
{% set search %}{% include "json/search.njk" %}{% endset %}
{% set social %}{% include "json/social.njk" %}{% endset %}
<script type="application/ld+json">
{{ search | minifyJson | safe }}
</script>
<script type="application/ld+json">
{{ social | minifyJson | safe }}
</script>
{% set search %}
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "{{ metadata.url }}",
"potentialAction": {
"@type": "SearchAction",
"target": "{{ metadata.url }}/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
{% endset %}
<script type="application/ld+json">
{{ search | minifyJson | safe }}
</script>
{% set social %}
{
"@context": "http://schema.org",
"@type": "Person",
"name": "{{ metadata.title }}",
"url": "{{ metadata.url }}",
"sameAs": [
"{{ metadata.author.social.facebook }}",
"{{ metadata.author.social.twitter }}",
"{{ metadata.author.social.github }}"
]
}
{% endset %}
<script type="application/ld+json">
{{ social | minifyJson | safe }}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment