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

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

feat(images): accent-gradient placeholder while covers load + fade-in

Cover tiles/cards now show an accent-coloured gradient placeholder while the image loads
(instead of a white flash), and the cover fades in once loaded. Cached images stay instant.
Makes image-heavy pages feel responsive even before thumbnails finish.

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