source: Klonkt/src/views/partials/post-card.ejs@ 38120c7

main
Last change on this file since 38120c7 was 38120c7, checked in by roboburr <roboburr@…>, 2 months ago

fix(feed): video covers fill the square thumbnail (object-fit:cover), centered — incl. desktop

The desktop list-cover rule was .post-list-cover img (img only), so a federated <video> cover was
unstyled = rendered at its intrinsic size (e.g. 640x360), overflowing the square slot from the
top-left. Add video to that rule so it gets width/height:100% + object-fit:cover + center (fill the
square, keep aspect, crop the overflow). Reverted the earlier object-fit:contain — the ask is cover,
not letterbox. style.css buster 65 -> 66.

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 9.8 KB
Line 
1<%
2// Post list item — MOBILE-FIRST.
3//
4// <768px (default):
5// Vertical stack — full-bleed 16:9 cover on top, content below.
6// Whole card is tappable (one big <a> wrapping everything).
7// Active state: scale(0.985) + opacity dim.
8//
9// ≥768px (desktop):
10// v9 pattern — 120px square cover left, content right.
11// Hover state on cover. Tap-target stays large.
12
13const _base = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
14const _external = post.external_url || null;
15const _href = _external || (_base + '/' + post.slug);
16const _ext = !!_external;
17const _src = post.source_name || '';
18const _hasCover = !!post.cover_image_url || !!post.cover_video_url;
19const _typeLabel = (post.type && post.type !== 'overig' && post.type !== 'post') ? post.type : '';
20const _isPinned = !!post.pinned;
21const _isBoost = !!post.isBoost;
22const _isDraft = post.status && post.status !== 'published';
23
24function _ddmmyyyy(iso) {
25 if (!iso) return '';
26 const d = new Date(iso);
27 if (isNaN(d.getTime())) return '';
28 const pad = n => String(n).padStart(2, '0');
29 return pad(d.getDate()) + '-' + pad(d.getMonth() + 1) + '-' + d.getFullYear();
30}
31
32let _tags = [];
33if (post.tags) {
34 if (Array.isArray(post.tags)) _tags = post.tags;
35 else if (typeof post.tags === 'string') {
36 try {
37 const parsed = JSON.parse(post.tags);
38 _tags = Array.isArray(parsed) ? parsed : post.tags.split(',').map(t => t.trim()).filter(Boolean);
39 } catch (e) {
40 _tags = post.tags.split(',').map(t => t.trim()).filter(Boolean);
41 }
42 }
43}
44%>
45<li class="post-list-item<%= (_hasCover || post.nsfw) ? ' has-cover' : '' %><%= (_isPinned || _isBoost) ? ' is-pinned' : '' %>">
46
47 <% if (_hasCover) { %>
48 <a class="post-list-cover<%= post.nsfw ? ' nsfw-media' : '' %>" href="<%= _href %>"
49 <% if (_ext) { %>target="_blank" rel="noopener"<% } else { %>hx-get="<%= _href %>?partial=1" hx-target="#pcms-main" hx-swap="innerHTML" hx-push-url="<%= _href %>" hx-indicator="#pcms-loading"<% } %>
50 aria-label="<%= post.title || '(zonder titel)' %>" tabindex="-1">
51 <% if (post.cover_image_url) { %><img src="<%= thumb(post.cover_image_url, 480) %>"
52 srcset="<%= thumb(post.cover_image_url, 320) %> 320w, <%= thumb(post.cover_image_url, 640) %> 640w, <%= thumb(post.cover_image_url, 1280) %> 1280w"
53 sizes="(min-width: 768px) 120px, 100vw"
54 alt="" loading="lazy" decoding="async"<% if (post.cover_video_url) { %> data-ios-mp4="<%= post.cover_video_url %>"<% } %>>
55 <% } else if (post.cover_video_url) { %><video src="<%= post.cover_video_url %>" autoplay loop muted playsinline></video><% } %>
56 <% if (post.nsfw) { %><span class="nsfw-veil"><span class="nsfw-veil-label">🔞 <%= post.content_warning || t('post.nsfw_warning') %></span><span class="nsfw-veil-btn"><%= t('post.nsfw_show') %></span></span><% } %>
57 </a>
58 <% } else if (post.nsfw) { %>
59 <a class="post-list-cover nsfw-media" href="<%= _href %>"
60 <% if (_ext) { %>target="_blank" rel="noopener"<% } else { %>hx-get="<%= _href %>?partial=1" hx-target="#pcms-main" hx-swap="innerHTML" hx-push-url="<%= _href %>" hx-indicator="#pcms-loading"<% } %>
61 aria-label="<%= post.title || '(zonder titel)' %>" tabindex="-1">
62 <span class="nsfw-veil"><span class="nsfw-veil-label">🔞 <%= post.content_warning || t('post.nsfw_warning') %></span><span class="nsfw-veil-btn"><%= t('post.nsfw_show') %></span></span>
63 </a>
64 <% } %>
65
66 <div class="post-list-body">
67 <div class="post-list-meta mono">
68 <% if (_isBoost) { %><span class="post-list-pin post-list-boost" aria-label="Boost"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg></span><% } else if (_isPinned) { %><span class="post-list-pin" aria-label="Vastgepind"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="12" y1="17" x2="12" y2="22"/><path d="M5 17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1v4.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24z"/></svg></span><% } %>
69 <time datetime="<%= post.published_at || post.created_at %>"><%= _ddmmyyyy(post.published_at || post.created_at) %></time>
70 <% if (_src) { %><span class="post-list-type">&middot; via <%= _src %></span><% } %>
71 <% if (_typeLabel) { %>
72 <span class="post-list-type">· <%= _typeLabel.charAt(0).toUpperCase() + _typeLabel.slice(1) %></span>
73 <% } %>
74 <% if (_isDraft) { %>
75 <span class="post-list-type post-list-draft">· concept</span>
76 <% } %>
77 </div>
78
79 <h3 class="post-list-title">
80 <a href="<%= _href %>"
81 <% if (_ext) { %>target="_blank" rel="noopener"<% } else { %>hx-get="<%= _href %>?partial=1" hx-target="#pcms-main" hx-swap="innerHTML" hx-push-url="<%= _href %>" hx-indicator="#pcms-loading"<% } %>>
82 <%= post.title || '(zonder titel)' %>
83 </a>
84 </h3>
85
86 <% if (post.excerpt) { %>
87 <p class="post-list-excerpt"><%= post.excerpt %></p>
88 <% } %>
89
90 <% if (_tags.length) { %>
91 <div class="post-list-tags">
92 <% _tags.forEach(function(t) { %>
93 <a href="<%= _base %>/tag/<%= encodeURIComponent(t) %>" class="tag-chip"
94 hx-get="<%= _base %>/tag/<%= encodeURIComponent(t) %>?partial=1" hx-target="#pcms-main"
95 hx-swap="innerHTML" hx-push-url="<%= _base %>/tag/<%= encodeURIComponent(t) %>"
96 hx-indicator="#pcms-loading">#<%= t %></a>
97 <% }); %>
98 </div>
99 <% } %>
100 </div>
101</li>
102
103<style>
104/* ============================================================
105 POST-LIST-ITEM — MOBILE-FIRST OVERRIDE
106 The base v9 styles in /assets/css/style.css use a desktop
107 120×120 grid by default. We flip that: stacked on mobile,
108 side-by-side on ≥768px.
109 ============================================================ */
110
111/* Reset v9's grid on mobile and stack vertically */
112@media (max-width: 767px) {
113 .post-list {
114 gap: 2rem;
115 }
116 .post-list-item {
117 display: flex !important;
118 flex-direction: column;
119 grid-template-columns: none !important;
120 gap: .85rem !important;
121 padding-bottom: 2rem;
122 /* Active feedback for the whole card row */
123 transition: transform 120ms ease, opacity 120ms ease;
124 }
125 .post-list-item:active {
126 transform: scale(0.985);
127 opacity: 0.85;
128 }
129 .post-list-item:last-child {
130 border-bottom: none;
131 padding-bottom: 0;
132 }
133
134 /* Cover: full-bleed of the container, 16:9 ratio, no border-radius
135 on small phones (edge-to-edge feels app-native). 8px radius from 480px+. */
136 .post-list-cover {
137 aspect-ratio: 16 / 9 !important;
138 width: 100% !important;
139 border-radius: 0 !important;
140 /* Negative margin to break out of .container's padding */
141 margin-left: calc(-1 * clamp(1.25rem, 4vw, 2rem));
142 margin-right: calc(-1 * clamp(1.25rem, 4vw, 2rem));
143 width: calc(100% + 2 * clamp(1.25rem, 4vw, 2rem)) !important;
144 /* Accent-gradient placeholder shown while the cover loads (the image fades in over it). */
145 background-image: linear-gradient(135deg,
146 color-mix(in srgb, var(--accent, #888) 22%, var(--paper-2)) 0%,
147 color-mix(in srgb, var(--accent, #888) 6%, var(--paper-2)) 100%);
148 }
149 .post-list-cover img, .post-list-cover video {
150 width: 100%; height: 100%;
151 object-fit: cover;
152 display: block;
153 transition: opacity .4s ease;
154 }
155 .post-list-cover img.is-loading { opacity: 0; }
156
157 /* Re-apply rounded corners on slightly larger phones */
158 @media (min-width: 480px) {
159 .post-list-cover {
160 border-radius: var(--radius) !important;
161 margin-left: 0 !important;
162 margin-right: 0 !important;
163 width: 100% !important;
164 }
165 }
166
167 /* Larger title for mobile readability */
168 .post-list-title {
169 font-size: 1.45rem !important;
170 line-height: 1.2 !important;
171 }
172 .post-list-excerpt {
173 font-size: 1rem !important;
174 color: var(--ink-soft) !important;
175 line-height: 1.55 !important;
176 }
177 .post-list-meta {
178 font-size: .8rem !important;
179 gap: .5rem !important;
180 }
181
182 /* Pinned indicator */
183 .post-list-item.is-pinned .post-list-title a {
184 /* No visual change on title — the ★ in meta is enough */
185 }
186
187 /* Tap targets for tags */
188 .post-list-tags { gap: .4rem; }
189 .tag-chip {
190 min-height: 32px;
191 display: inline-flex;
192 align-items: center;
193 padding: .2rem .65rem;
194 }
195}
196
197/* ============================================================
198 DESKTOP — keep v9's 120px-square pattern (style.css does this)
199 We just enforce the layout here for clarity + override safety.
200 ============================================================ */
201@media (min-width: 768px) {
202 .post-list-item.has-cover {
203 display: grid !important;
204 grid-template-columns: 120px 1fr !important;
205 gap: 1.25rem !important;
206 }
207 .post-list-item:not(.has-cover) {
208 grid-template-columns: 1fr !important;
209 }
210 .post-list-cover {
211 aspect-ratio: 1 !important;
212 border-radius: var(--radius) !important;
213 }
214 /* Hover lift on desktop (touch devices use :active above) */
215 @media (hover: hover) {
216 .post-list-cover {
217 transition: transform 200ms ease;
218 }
219 .post-list-item:hover .post-list-cover {
220 transform: scale(1.02);
221 }
222 }
223}
224
225/* ============================================================
226 PIN + DRAFT INDICATORS (shared)
227 ============================================================ */
228.post-list-pin {
229 color: var(--accent);
230 margin-right: .35rem;
231 display: inline-flex;
232 align-items: center;
233 vertical-align: middle;
234}
235.post-list-pin svg { width: 13px; height: 13px; display: block; }
236.post-list-boost { color: #2fa85a; }
237.post-list-draft {
238 color: var(--accent);
239 font-style: italic;
240}
241</style>
Note: See TracBrowser for help on using the repository browser.