Skip to content

Commit cd6fcb5

Browse files
authored
Merge pull request #75 from thekid/feature/single-video-playback
If a content is formed of a single video, play in feed
2 parents ca44c00 + 06a45b6 commit cd6fcb5

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

src/main/handlebars/feed.handlebars

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,35 @@
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+
<div class="{{#if is.video}}is-video{{/if}} image" style="z-index: -{{@index}}">
67+
<img alt="{{title}}, {{date meta.dateTime format='d.m.Y H:i'}}" {{#unless ../@first}}loading="lazy"{{/unless}} src="/image/{{slug}}/thumb-{{name}}.webp" width="192">
68+
</div>
69+
{{/unless}}
70+
{{/each}}
71+
</div>
72+
</a>
73+
{{/if}}
5974

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

src/main/handlebars/layout.handlebars

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -598,22 +598,26 @@
598598
display: flex;
599599
isolation: isolate;
600600
601-
img {
602-
display: block;
601+
.image {
602+
position: relative;
603603
border: .25rem solid white;
604604
border-radius: .35rem;
605-
width: var(--_size);
606-
aspect-ratio: 1 / 1;
607-
object-fit: cover;
608605
box-shadow: .5rem .5rem 1rem rgb(0 0 0 / .2);
609606
transition: margin ease-in-out 150ms;
607+
width: var(--_size);
608+
height: var(--_size);
609+
}
610+
611+
.image img {
612+
width: 100%;
613+
height: 100%;
610614
}
611615
612-
img:not(:first-child) {
616+
.image:not(:first-child) {
613617
margin-left: calc(-1 * var(--_overlap));
614618
}
615619
616-
&:hover img:not(:first-child) {
620+
&:hover .image:not(:first-child) {
617621
margin-left: 1rem;
618622
}
619623
}

0 commit comments

Comments
 (0)