Skip to content

Commit 5eadb9c

Browse files
committed
If a content is formed of a single video, play in feed
1 parent ca44c00 commit 5eadb9c

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/main/handlebars/feed.handlebars

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,33 @@
4242
{{> partials/weather in=.}}
4343
</div>
4444

45-
<a class="images is-preview is-{{size-class (size images)}}" href="{{route this}}">
46-
{{#with images.0}}
47-
<div class="{{#if is.video}}is-video{{/if}} image">
48-
<img alt="{{title}}, {{date meta.dateTime format='d.m.Y H:i'}}" {{#unless first}}loading="lazy"{{/unless}} {{&dataset meta}} src="/image/{{slug}}/thumb-{{name}}.webp" width="1024">
49-
</div>
50-
{{/with}}
51-
<div class="more">
52-
{{#each images}}
53-
{{#unless (equals @index 0)}}
54-
<img alt="{{title}}, {{date meta.dateTime format='d.m.Y H:i'}}" {{#unless ../@first}}loading="lazy"{{/unless}} style="z-index: -{{@index}}" src="/image/{{slug}}/thumb-{{name}}.webp" width="192">
55-
{{/unless}}
56-
{{/each}}
45+
{{! Content formed of a single video can be played back inline directly }}
46+
{{#if (all (equals 1 (size images)) images.0.is.video)}}
47+
<div class="images is-single">
48+
{{#with images.0}}
49+
<div class="image">
50+
<video controls playsinline preload="metadata" width="100%" poster="/image/{{slug}}/thumb-{{name}}.webp" data-slug="{{slug}}">
51+
<source src="/image/{{slug}}/video-{{name}}.mp4" type="video/mp4">
52+
</video>
53+
</div>
54+
{{/with}}
5755
</div>
58-
</a>
56+
{{else}}
57+
<a class="images is-preview is-{{size-class (size images)}}" href="{{route this}}">
58+
{{#with images.0}}
59+
<div class="{{#if is.video}}is-video{{/if}} image">
60+
<img alt="{{title}}, {{date meta.dateTime format='d.m.Y H:i'}}" {{#unless first}}loading="lazy"{{/unless}} {{&dataset meta}} src="/image/{{slug}}/thumb-{{name}}.webp" width="1024">
61+
</div>
62+
{{/with}}
63+
<div class="more">
64+
{{#each images}}
65+
{{#unless (equals @index 0)}}
66+
<img alt="{{title}}, {{date meta.dateTime format='d.m.Y H:i'}}" {{#unless ../@first}}loading="lazy"{{/unless}} style="z-index: -{{@index}}" src="/image/{{slug}}/thumb-{{name}}.webp" width="192">
67+
{{/unless}}
68+
{{/each}}
69+
</div>
70+
</a>
71+
{{/if}}
5972

6073
<div class="content">
6174
{{& content}}
@@ -75,5 +88,20 @@
7588
</div>
7689
{{/inline}}
7790
{{#*inline "scripts"}}
91+
<script type="module">
92+
{{&use 'statistics'}}
93+
const statistics = new Statistics();
94+
{{#each elements}}
95+
{{#if (all (equals 1 (size images)) images.0.is.video)}}
96+
statistics.add('{{slug}}', '{{sign slug}}', 1500);
97+
{{/if}}
98+
{{/each}}
99+
100+
// Content formed of a single video has been watched once it's played back for more than 1.5 seconds
101+
for (const $video of document.querySelectorAll('video')) {
102+
$video.addEventListener('play', e => statistics.schedule($video.dataset['slug']));
103+
$video.addEventListener('pause', e => statistics.withdraw($video.dataset['slug']));
104+
}
105+
</script>
78106
{{/inline}}
79107
{{/layout}}

0 commit comments

Comments
 (0)