diff --git a/resources/layouts/_default/page.iframe.twig b/resources/layouts/_default/page.iframe.twig index 970f518ea..db2aac236 100644 --- a/resources/layouts/_default/page.iframe.twig +++ b/resources/layouts/_default/page.iframe.twig @@ -22,8 +22,8 @@ {%- if page.videos is defined ~%} {%- else ~%} diff --git a/resources/layouts/_default/page.oembed.twig b/resources/layouts/_default/page.oembed.twig index 17d35e8b2..5205c5efb 100644 --- a/resources/layouts/_default/page.oembed.twig +++ b/resources/layouts/_default/page.oembed.twig @@ -30,7 +30,9 @@ {%- endif ~%} "provider_name": "{{ site.title }}", "provider_url": "{{ url('/', {canonical: true}) }}", + {%- if author.name is defined ~%} "author_name": "{{ author.name }}", + {%- endif ~%} {%- if author.url is defined ~%} "author_url": "{{ author.url }}", {%- endif ~%} @@ -38,6 +40,8 @@ {%- if 'iframe' in page.output ~%} "embed_url": "{{ url(page, {canonical: true, format: 'iframe'}) }}", {%- endif ~%} + {%- if opengraph.description is defined ~%} "description": "{{ opengraph.description }}" + {%- endif ~%} } {% endblock %} \ No newline at end of file diff --git a/resources/layouts/partials/jsonld.js.twig b/resources/layouts/partials/jsonld.js.twig index 3f0209b6d..cd5242e65 100644 --- a/resources/layouts/partials/jsonld.js.twig +++ b/resources/layouts/partials/jsonld.js.twig @@ -118,14 +118,16 @@ "@context": "https://schema.org", "@type": "VideoObject", "name": "{{ title|default(page.title)|e }}", + {%- if page.description is defined ~%} "description": "{{ page.description|e }}", - {%- if page.poster is defined ~%} + {%- endif ~%} "thumbnailUrl": [ "{{ url(asset(page.poster), {canonical: true}) }}" ], - {%- endif ~%} "uploadDate": "{{ page.date|date('Y-m-dTH:i:sP') }}", - "duration": "PT1M54S", + {%- if page.duration is defined ~%} + "duration": "{{ page.duration|duration_to_iso8601 }}", + {%- endif ~%} "contentUrl": "{{ url(opengraph.video, {canonical: true}) }}", "embedUrl": "{{ url(page, {canonical: true, format: 'iframe'}) }}" } diff --git a/src/Renderer/Extension/Core.php b/src/Renderer/Extension/Core.php index 50a7c108b..2e0907221 100644 --- a/src/Renderer/Extension/Core.php +++ b/src/Renderer/Extension/Core.php @@ -146,6 +146,8 @@ public function getFilters(): array new \Twig\TwigFilter('preg_match_all', [$this, 'pregMatchAll']), new \Twig\TwigFilter('hex_to_rgb', [$this, 'hexToRgb']), new \Twig\TwigFilter('splitline', [$this, 'splitLine']), + // date + new \Twig\TwigFilter('duration_to_iso8601', ['\Cecil\Util\Date', 'durationToIso8601']), ]; } diff --git a/src/Util/Date.php b/src/Util/Date.php index 5baf6843e..ffcd423ad 100644 --- a/src/Util/Date.php +++ b/src/Util/Date.php @@ -50,4 +50,18 @@ public static function toDatetime($date): \DateTime return new \DateTime($date); } + + /** + * Duration in seconds to ISO 8601. + * e.g.: '00:00:46.70' -> 'T0M46S' + */ + public static function durationToIso8601(string $duration): string + { + $time = new \DateTime($duration); + $midnight = new \DateTime(); + $midnight->setTime(0, 0); + $period = $midnight->diff($time); + + return $period->format('T%iM%SS'); + } } diff --git a/tests/fixtures/website/layouts/video.html.twig b/tests/fixtures/website/layouts/video.html.twig new file mode 100644 index 000000000..608d26362 --- /dev/null +++ b/tests/fixtures/website/layouts/video.html.twig @@ -0,0 +1,10 @@ +{% extends '_default/page.html.twig' %} + +{% block content %} + +{% endblock %} \ No newline at end of file diff --git a/tests/fixtures/website/pages/Assets/video.md b/tests/fixtures/website/pages/Assets/video.md new file mode 100644 index 000000000..e9268ea28 --- /dev/null +++ b/tests/fixtures/website/pages/Assets/video.md @@ -0,0 +1,12 @@ +--- +title: Video +image: video/poster.png + +duration: 00:00:13 +videos: + - video/test.mp4 +poster: video/poster.png + +output: [html, iframe, oembed] +layout: video +--- diff --git a/tests/fixtures/website/static/video/poster.png b/tests/fixtures/website/static/video/poster.png new file mode 100644 index 000000000..f1765bad0 Binary files /dev/null and b/tests/fixtures/website/static/video/poster.png differ