Skip to content

Instantly share code, notes, and snippets.

@apsolut
Created July 2, 2024 15:44
Show Gist options
  • Save apsolut/ff1f71079b2c4eaf8a5fd30d3aa0f4ac to your computer and use it in GitHub Desktop.
Save apsolut/ff1f71079b2c4eaf8a5fd30d3aa0f4ac to your computer and use it in GitHub Desktop.
{# add macro for video schema.org #}
{% import '../../macros/video-schemaorg.html' as video_macros %}
{{ video_macros.video_schema(module.options_video) }}
{% macro video_schema(options_video) %}
{% if module.options_video.enable_video %}
{% require_head %}
{% set videoName = module.options_video.video_name %}
{% set videoDesc = module.options_video.video_description %}
{% set videoThumb = module.options_video.video_thumb.src %}
{% set videoDate = module.options_video.video_date %}
{% set videoDateFormated = videoDate|datetimeformat("%Y-%m-%dT%H:%M:%S%z") %}
{% set videoURL = module.options_video.video_url %}
{% set videoRegion = module.options_video.video_region %}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "VideoObject",
"name": "{{ videoName }}",
"description": "{{ videoDesc }}",
"thumbnailUrl": [
"{{ videoThumb }}"
],
"uploadDate": "{{ videoDateFormated }}",
"contentUrl": "{{ videoURL }}"
{% if videoRegion %}
,"regionsAllowed": "{{ videoRegion }}"
{% endif %}
}
</script>
{% end_require_head %}
{% endif %}
{% endmacro %}
@apsolut
Copy link
Author

apsolut commented Jul 3, 2024

This was original form:

{% if module.options_video.enable_video %}
	{% require_head %}
		{% set videoName =  module.options_video.video_name %}
		{% set videoDesc =  module.options_video.video_description %}
		{% set videoThumb =  module.options_video.video_thumb.src %}
		{% set videoDate =  module.options_video.video_date %}
		{% set videoDateFormated =  videoDate|datetimeformat("%Y-%m-%dT%H:%M:%S%z") %}
		{% set videoURL =  module.options_video.video_url %}
		{% set videoRegion =  module.options_video.video_region %}
		<script type="application/ld+json">
			
			{
				"@context": "https://schema.org",
				"@type": "VideoObject",
				"name": "{{videoName}}",
				"description": "{{videoDesc}}",
				"thumbnailUrl": [
					"{{videoThumb}}"
				],
				"uploadDate": "{{videoDateFormated}}", 
				"contentUrl": "{{videoURL}}"
				{% if videoRegion %}
					, "regionsAllowed": "{{videoRegion}}"
				{% endif %}
			}
		</script>
	{% end_require_head %}
	{% endif %}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment