source: Klonkt/src/views/partials/post-card.ejs@ 93b147d

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

fix(feed): serve full-resolution covers on mobile (responsive srcset)

The timeline card cover used a fixed 256px thumbnail — right for the 120px desktop
thumb, but the cover is full-width (100vw) on mobile, so a ~430px phone at 3x DPR
upscaled the 256px image ~5x → blurry (most visible in the PWA).

  • src/views/partials/post-card.ejs — cover <img> now uses srcset (320/640/1280w) + sizes "(min-width:768px) 120px, 100vw", so the browser picks ~1280 for the full-width mobile cover and ~320 for the small desktop thumb (no over-fetch)

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

  • Property mode set to 100644
File size: 9.5 KB
RevLine 
[7bc636b]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
[7963a6e]13const _base = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
[43dbf9c]14const _external = post.external_url || null;
15const _href = _external || (_base + '/' + post.slug);
16const _ext = !!_external;
17const _src = post.source_name || '';
[7bc636b]18const _hasCover = !!post.cover_image_url;
19const _typeLabel = (post.type && post.type !== 'overig' && post.type !== 'post') ? post.type : '';
20const _isPinned = !!post.pinned;
[c7c7f02]21const _isBoost = !!post.isBoost;
[7bc636b]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%>
[515cf1a]45<li class="post-list-item<%= (_hasCover || post.nsfw) ? ' has-cover' : '' %><%= (_isPinned || _isBoost) ? ' is-pinned' : '' %>">
[7bc636b]46
47 <% if (_hasCover) { %>
[837fc9c]48 <a class="post-list-cover<%= post.nsfw ? ' nsfw-media' : '' %>" href="<%= _href %>"
[43dbf9c]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"<% } %>
[7bc636b]50 aria-label="<%= post.title || '(zonder titel)' %>" tabindex="-1">
[93b147d]51 <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">
[b7d4458]55 <% 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><% } %>
[7bc636b]56 </a>
[515cf1a]57 <% } else if (post.nsfw) { %>
58 <a class="post-list-cover nsfw-media" href="<%= _href %>"
59 <% 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"<% } %>
60 aria-label="<%= post.title || '(zonder titel)' %>" tabindex="-1">
61 <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>
62 </a>
[7bc636b]63 <% } %>
64
65 <div class="post-list-body">
66 <div class="post-list-meta mono">
[69e7a79]67 <% 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><% } %>
[7bc636b]68 <time datetime="<%= post.published_at || post.created_at %>"><%= _ddmmyyyy(post.published_at || post.created_at) %></time>
[43dbf9c]69 <% if (_src) { %><span class="post-list-type">&middot; via <%= _src %></span><% } %>
[7bc636b]70 <% if (_typeLabel) { %>
71 <span class="post-list-type">· <%= _typeLabel.charAt(0).toUpperCase() + _typeLabel.slice(1) %></span>
72 <% } %>
73 <% if (_isDraft) { %>
74 <span class="post-list-type post-list-draft">· concept</span>
75 <% } %>
76 </div>
77
78 <h3 class="post-list-title">
79 <a href="<%= _href %>"
[43dbf9c]80 <% 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"<% } %>>
[7bc636b]81 <%= post.title || '(zonder titel)' %>
82 </a>
83 </h3>
84
85 <% if (post.excerpt) { %>
86 <p class="post-list-excerpt"><%= post.excerpt %></p>
87 <% } %>
88
89 <% if (_tags.length) { %>
90 <div class="post-list-tags">
91 <% _tags.forEach(function(t) { %>
[7963a6e]92 <a href="<%= _base %>/tag/<%= encodeURIComponent(t) %>" class="tag-chip"
93 hx-get="<%= _base %>/tag/<%= encodeURIComponent(t) %>?partial=1" hx-target="#pcms-main"
94 hx-swap="innerHTML" hx-push-url="<%= _base %>/tag/<%= encodeURIComponent(t) %>"
[7bc636b]95 hx-indicator="#pcms-loading">#<%= t %></a>
96 <% }); %>
97 </div>
98 <% } %>
99 </div>
100</li>
101
102<style>
103/* ============================================================
104 POST-LIST-ITEM — MOBILE-FIRST OVERRIDE
105 The base v9 styles in /assets/css/style.css use a desktop
106 120×120 grid by default. We flip that: stacked on mobile,
107 side-by-side on ≥768px.
108 ============================================================ */
109
110/* Reset v9's grid on mobile and stack vertically */
111@media (max-width: 767px) {
112 .post-list {
113 gap: 2rem;
114 }
115 .post-list-item {
116 display: flex !important;
117 flex-direction: column;
118 grid-template-columns: none !important;
119 gap: .85rem !important;
120 padding-bottom: 2rem;
121 /* Active feedback for the whole card row */
122 transition: transform 120ms ease, opacity 120ms ease;
123 }
124 .post-list-item:active {
125 transform: scale(0.985);
126 opacity: 0.85;
127 }
128 .post-list-item:last-child {
129 border-bottom: none;
130 padding-bottom: 0;
131 }
132
133 /* Cover: full-bleed of the container, 16:9 ratio, no border-radius
134 on small phones (edge-to-edge feels app-native). 8px radius from 480px+. */
135 .post-list-cover {
136 aspect-ratio: 16 / 9 !important;
137 width: 100% !important;
138 border-radius: 0 !important;
139 /* Negative margin to break out of .container's padding */
140 margin-left: calc(-1 * clamp(1.25rem, 4vw, 2rem));
141 margin-right: calc(-1 * clamp(1.25rem, 4vw, 2rem));
142 width: calc(100% + 2 * clamp(1.25rem, 4vw, 2rem)) !important;
[a64d705]143 /* Accent-gradient placeholder shown while the cover loads (the image fades in over it). */
144 background-image: linear-gradient(135deg,
145 color-mix(in srgb, var(--accent, #888) 22%, var(--paper-2)) 0%,
146 color-mix(in srgb, var(--accent, #888) 6%, var(--paper-2)) 100%);
[7bc636b]147 }
148 .post-list-cover img {
149 width: 100%; height: 100%;
150 object-fit: cover;
151 display: block;
[a64d705]152 transition: opacity .4s ease;
[7bc636b]153 }
[a64d705]154 .post-list-cover img.is-loading { opacity: 0; }
[7bc636b]155
156 /* Re-apply rounded corners on slightly larger phones */
157 @media (min-width: 480px) {
158 .post-list-cover {
159 border-radius: var(--radius) !important;
160 margin-left: 0 !important;
161 margin-right: 0 !important;
162 width: 100% !important;
163 }
164 }
165
166 /* Larger title for mobile readability */
167 .post-list-title {
168 font-size: 1.45rem !important;
169 line-height: 1.2 !important;
170 }
171 .post-list-excerpt {
172 font-size: 1rem !important;
173 color: var(--ink-soft) !important;
174 line-height: 1.55 !important;
175 }
176 .post-list-meta {
177 font-size: .8rem !important;
178 gap: .5rem !important;
179 }
180
181 /* Pinned indicator */
182 .post-list-item.is-pinned .post-list-title a {
183 /* No visual change on title — the ★ in meta is enough */
184 }
185
186 /* Tap targets for tags */
187 .post-list-tags { gap: .4rem; }
188 .tag-chip {
189 min-height: 32px;
190 display: inline-flex;
191 align-items: center;
192 padding: .2rem .65rem;
193 }
194}
195
196/* ============================================================
197 DESKTOP — keep v9's 120px-square pattern (style.css does this)
198 We just enforce the layout here for clarity + override safety.
199 ============================================================ */
200@media (min-width: 768px) {
201 .post-list-item.has-cover {
202 display: grid !important;
203 grid-template-columns: 120px 1fr !important;
204 gap: 1.25rem !important;
205 }
206 .post-list-item:not(.has-cover) {
207 grid-template-columns: 1fr !important;
208 }
209 .post-list-cover {
210 aspect-ratio: 1 !important;
211 border-radius: var(--radius) !important;
212 }
213 /* Hover lift on desktop (touch devices use :active above) */
214 @media (hover: hover) {
215 .post-list-cover {
216 transition: transform 200ms ease;
217 }
218 .post-list-item:hover .post-list-cover {
219 transform: scale(1.02);
220 }
221 }
222}
223
224/* ============================================================
225 PIN + DRAFT INDICATORS (shared)
226 ============================================================ */
227.post-list-pin {
228 color: var(--accent);
229 margin-right: .35rem;
[69e7a79]230 display: inline-flex;
231 align-items: center;
232 vertical-align: middle;
[7bc636b]233}
[69e7a79]234.post-list-pin svg { width: 13px; height: 13px; display: block; }
235.post-list-boost { color: #2fa85a; }
[7bc636b]236.post-list-draft {
237 color: var(--accent);
238 font-style: italic;
239}
240</style>
Note: See TracBrowser for help on using the repository browser.