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

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

feat(nsfw): custom content-warning text + blur in the Cirkel

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