source: Klonkt/src/views/pages/post.ejs@ c901131

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

style(activitypub): nicer reply-address field + localized placeholder

Pill-style input matching the button, accent focus ring, localized placeholder
(@naam@…) via data-fedi-ph instead of the hardcoded @jij.

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

  • Property mode set to 100644
File size: 19.5 KB
Line 
1<%
2// In hub mode the site is accessible under /user/<slug>; all site-scoped links
3// (tag, edit, delete, comments) must carry that prefix otherwise they fall back
4// to the primary site → 404 / wrong site. In solo mode _base = ''.
5const _base = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
6%>
7<article class="container post-page">
8
9 <%# Navigation across ALL posts — ABOVE the post (shared partial). %>
10 <%- include('../partials/post-nav', { newerPost: newerPost, olderPost: olderPost }) %>
11
12 <% if (post.cover_image_url) { %>
13 <figure class="post-cover">
14 <img src="<%= post.cover_image_url %>" alt="">
15 </figure>
16 <% } %>
17
18 <header class="post-header">
19 <h1 class="post-title"><%= post.title %></h1>
20 <div class="post-meta">
21 <a class="author" href="/users/<%= encodeURIComponent(post.author_username) %>"
22 hx-get="/users/<%= encodeURIComponent(post.author_username) %>?partial=1"
23 hx-target="#pcms-main" hx-swap="innerHTML"
24 hx-push-url="/users/<%= encodeURIComponent(post.author_username) %>"
25 hx-indicator="#pcms-loading"><%= post.author_username %></a>
26 <span class="meta-sep">·</span>
27 <time datetime="<%= post.published_at || post.created_at %>"><%= formatDate(post.published_at || post.created_at) %></time>
28 <% if (post.status !== 'published') { %>
29 <span class="meta-sep">·</span>
30 <span class="status-badge status-<%= post.status %>"><%= post.status %></span>
31 <% } %>
32 </div>
33 <% if (post.status === 'published') { %>
34 <div class="post-like-row">
35 <%- include('../partials/like-button', { post: post, likedByMe: (typeof likedByMe !== 'undefined' && likedByMe), likeCount: (typeof likeCount !== 'undefined' ? likeCount : 0), loggedIn: !!user, loginNext: _base + '/' + post.slug }) %>
36 </div>
37 <% } %>
38 </header>
39
40 <div class="post-content">
41 <%- post.content_html %>
42 </div>
43
44 <% if (post.tags && post.tags.length > 0) { %>
45 <div class="post-tags">
46 <% post.tags.forEach(t => { %>
47 <a class="tag" href="<%= _base %>/tag/<%= encodeURIComponent(t) %>"
48 hx-get="<%= _base %>/tag/<%= encodeURIComponent(t) %>?partial=1"
49 hx-target="#pcms-main" hx-swap="innerHTML"
50 hx-push-url="<%= _base %>/tag/<%= encodeURIComponent(t) %>"
51 hx-indicator="#pcms-loading">#<%= t %></a>
52 <% }); %>
53 </div>
54 <% } %>
55
56 <!-- Inline admin actions: only visible if user has permission -->
57 <% if (user && (permissions.canEditPost(user, post, site) || permissions.canDeletePost(user, post, site))) { %>
58 <aside class="post-actions">
59 <% if (permissions.canEditPost(user, post, site)) { %>
60 <a href="<%= _base %>/posts/<%= post.slug %>/edit" class="btn"
61 hx-get="<%= _base %>/posts/<%= post.slug %>/edit?partial=1" hx-target="#pcms-main"
62 hx-push-url="<%= _base %>/posts/<%= post.slug %>/edit" hx-indicator="#pcms-loading">
63 ✏️ Edit
64 </a>
65 <% } %>
66 <% if (permissions.canDeletePost(user, post, site)) { %>
67 <form method="post" action="<%= _base %>/posts/<%= post.slug %>/delete" style="display:inline" onsubmit="return confirm('Delete this post?')">
68 <button type="submit" class="btn btn-danger">🗑 Delete</button>
69 </form>
70 <% } %>
71 </aside>
72 <% } %>
73
74 <!-- Fediverse interactions (threaded: inbound replies/likes/boosts + our replies) -->
75 <% if (typeof fediverse !== 'undefined' && fediverse && fediverse.total > 0) { %>
76 <section class="post-fediverse post-comments" id="fediverse">
77 <h2 class="comments-heading"><%= t('fedi.heading') %></h2>
78 <p class="fedi-stats">
79 <span title="<%= t('fedi.likes') %>">⭐ <%= fediverse.likeCount %></span>
80 <span title="<%= t('fedi.boosts') %>">🔁 <%= fediverse.announceCount %></span>
81 <span title="<%= t('fedi.replies') %>">💬 <%= (fediverse.thread || []).length %></span>
82 </p>
83 <% if (fediverse.thread && fediverse.thread.length) { %>
84 <ol class="comments-list">
85 <% fediverse.thread.forEach(function(n){ %>
86 <li class="comment"><%- include('../partials/fedi-node', { n: n, t: t, canManageSite: (typeof canManageSite !== 'undefined' ? canManageSite : false), _base: _base, siteAvatar: (typeof siteAvatar !== 'undefined' ? siteAvatar : null), formatDateTime: formatDateTime }) %></li>
87 <% }); %>
88 </ol>
89 <% } %>
90 </section>
91 <% } %>
92
93 <!-- Reply via the fediverse (remote interaction: bounces to the visitor's own server) -->
94 <% var _postAbsUrl = (typeof ogOrigin !== 'undefined' && ogOrigin ? ogOrigin : '') + (typeof _base !== 'undefined' && _base ? _base : '') + '/' + post.slug; %>
95 <div class="post-fediverse-cta">
96 <button type="button" class="btn fedi-remote-reply-btn" data-fedi-uri="<%= _postAbsUrl %>" data-fedi-ph="<%= t('fedi.remote_ph') %>">
97 <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="9 17 4 12 9 7"/><path d="M20 18v-2a4 4 0 0 0-4-4H4"/></svg>
98 <%= t('fedi.remote_reply') %>
99 </button>
100 </div>
101 <script>
102 (function(){
103 if (window.__fediRemoteWired) return; window.__fediRemoteWired = true;
104 function go(raw, uri){
105 var d = (raw||'').trim().replace(/^@?[^@\s]*@/, '').replace(/^https?:\/\//i, '').replace(/\/.*$/, '').trim();
106 if (d) location.href = 'https://' + d + '/authorize_interaction?uri=' + encodeURIComponent(uri||'');
107 }
108 document.addEventListener('click', function(e){
109 var cancel = e.target.closest && e.target.closest('.fedi-remote-cancel');
110 if (cancel) { var f0 = cancel.closest('.fedi-remote-form'); if (f0) f0.remove(); return; }
111 var b = e.target.closest && e.target.closest('.fedi-remote-reply-btn');
112 if (!b) return;
113 e.preventDefault();
114 var mine = (b.nextElementSibling && b.nextElementSibling.classList && b.nextElementSibling.classList.contains('fedi-remote-form')) ? b.nextElementSibling : null;
115 var any = document.querySelector('.fedi-remote-form'); if (any) any.remove();
116 if (mine) return; // clicking again closes it
117 var f = document.createElement('form');
118 f.className = 'fedi-remote-form';
119 f.dataset.uri = b.getAttribute('data-fedi-uri') || '';
120 f.innerHTML = '<input type="text" autocomplete="off" spellcheck="false">'
121 + '<button type="submit" class="btn btn-primary fedi-remote-go" aria-label="ok">&rarr;</button>'
122 + '<button type="button" class="fedi-remote-cancel" aria-label="x">&times;</button>';
123 var inp = f.querySelector('input');
124 inp.placeholder = b.getAttribute('data-fedi-ph') || '@name@mastodon.social';
125 b.parentNode.insertBefore(f, b.nextSibling);
126 inp.focus();
127 });
128 document.addEventListener('submit', function(e){
129 var f = e.target.closest && e.target.closest('.fedi-remote-form');
130 if (!f) return;
131 e.preventDefault();
132 go(f.querySelector('input').value, f.dataset.uri);
133 });
134 })();
135 </script>
136
137
138 <%# ── Related posts (3-card grid) ─────────────────────────────
139 Always shown if at least one related post exists. Selection logic
140 lives server-side: same-tag posts ranked by overlap, falling back
141 to most-recent if there's no tag overlap. %>
142 <% if (relatedPosts && relatedPosts.length > 0) { %>
143 <section class="post-related" aria-labelledby="related-heading">
144 <h2 class="post-related-heading" id="related-heading"><%= t('related.title') %></h2>
145 <ul class="post-related-grid">
146 <% relatedPosts.forEach(function(rp) { %>
147 <li class="post-related-card">
148 <a href="<%= rp._urlBase || '' %>/<%= rp.slug %>"<% if (!rp._urlBase) { %>
149 hx-get="/<%= rp.slug %>?partial=1" hx-target="#pcms-main"
150 hx-push-url="/<%= rp.slug %>" hx-indicator="#pcms-loading"<% } %>>
151 <% if (rp.cover_image_url) { %>
152 <span class="post-related-cover"
153 style="background-image: url('<%= rp.cover_image_url %>')"
154 aria-hidden="true"></span>
155 <% } else { %>
156 <span class="post-related-cover post-related-cover--empty" aria-hidden="true"></span>
157 <% } %>
158 <span class="post-related-meta">
159 <span class="post-related-date"><%= formatDate(rp.published_at) %></span>
160 <span class="post-related-title"><%= rp.title %></span>
161 </span>
162 </a>
163 </li>
164 <% }); %>
165 </ul>
166 </section>
167 <% } %>
168
169</article>
170<style>
171.post-page { max-width: 720px; margin: 0.5rem auto 2rem; padding: 0 1rem; }
172.post-cover { margin: 0 0 2rem; border-radius: 8px; overflow: hidden; }
173.post-cover img { width: 100%; height: auto; display: block; }
174.post-header { margin-bottom: 2rem; }
175.post-title { font-family: var(--font-display, serif); font-size: 2.5rem; line-height: 1.1; margin: 0 0 1rem; }
176@media (max-width: 600px) { .post-title { font-size: 1.85rem; } }
177.post-meta { font-size: 0.9rem; color: var(--ink-muted); }
178.author { font-weight: 500; color: var(--ink-soft); text-decoration: none; }
179.author:hover { color: var(--accent); }
180.post-content { font-family: var(--font-body, serif); font-size: 1.1rem; line-height: 1.7; color: var(--ink); }
181.post-content p { margin: 1.2em 0; }
182.post-like-row { margin-top: 1rem; }
183.like-btn {
184 display: inline-flex; align-items: center; gap: 0.45rem;
185 padding: 0.4rem 0.85rem; border: 1px solid var(--rule); border-radius: 999px;
186 background: var(--paper-2); color: var(--ink); font: inherit; font-size: 0.95rem;
187 cursor: pointer; text-decoration: none; transition: border-color 120ms, color 120ms, background 120ms;
188}
189.like-btn:hover { border-color: var(--accent); }
190.like-btn .like-heart { font-size: 1.1rem; line-height: 1; }
191.like-btn.is-liked { border-color: var(--accent); color: var(--accent); }
192.like-btn.is-liked .like-heart { color: var(--accent); }
193.like-btn .like-count { font-variant-numeric: tabular-nums; }
194.post-content h2 { font-family: var(--font-display, serif); font-size: 1.6rem; margin: 2rem 0 1rem; }
195.post-content h3 { font-family: var(--font-display, serif); font-size: 1.3rem; margin: 1.5rem 0 0.75rem; }
196.post-content a { color: var(--accent); }
197.post-content code { background: var(--paper-2); padding: 0.1em 0.4em; border-radius: 3px; font-family: var(--font-mono, monospace); font-size: 0.9em; }
198.post-content pre { background: var(--paper-2); padding: 1rem; border-radius: 6px; overflow-x: auto; }
199.post-content blockquote { border-left: 3px solid var(--accent); padding-left: 1rem; margin: 1.5rem 0; color: var(--ink-soft); font-style: italic; }
200.post-content img { max-width: 100%; height: auto; border-radius: 6px; }
201.post-tags { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 2rem 0; }
202.tag { background: var(--paper-2); color: var(--ink-soft); padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.85rem; text-decoration: none; transition: background 120ms, color 120ms; }
203.tag:hover { background: var(--accent); color: white; }
204.post-actions { display: flex; gap: 0.5rem; margin: 2rem 0; padding: 1rem; background: var(--paper-2); border-radius: 6px; flex-wrap: wrap; }
205
206/* ============================================================
207 Comments
208 ============================================================ */
209.post-comments {
210 margin-top: 3rem;
211 padding-top: 2rem;
212 border-top: 1px solid var(--rule);
213}
214.comments-heading {
215 font-family: var(--font-display, serif);
216 font-size: 1.5rem;
217 margin: 0 0 1.5rem;
218}
219.comments-empty { color: var(--ink-muted, var(--ink-soft)); margin: 0 0 1.5rem; }
220.comments-pending-flash {
221 background: rgba(40, 160, 90, 0.15);
222 color: #2a9d5e;
223 border: 1px solid rgba(40, 160, 90, 0.3);
224 padding: 0.75rem 1rem;
225 border-radius: 6px;
226 margin-bottom: 1rem;
227 font-size: 0.9rem;
228}
229.comments-empty a { color: var(--accent); }
230
231.comments-list, .comment-replies {
232 list-style: none;
233 padding: 0;
234 margin: 0 0 2rem;
235}
236
237.comment {
238 display: flex;
239 gap: 0.85rem;
240 padding: 1rem 0;
241 border-top: 1px solid var(--rule);
242}
243.comments-list > .comment:first-child { border-top: 0; padding-top: 0; }
244
245.comment-avatar {
246 flex-shrink: 0;
247 width: 40px;
248 height: 40px;
249 border-radius: 50%;
250 background: var(--paper-2);
251 border: 1px solid var(--rule);
252 overflow: hidden;
253 display: inline-flex;
254 align-items: center;
255 justify-content: center;
256}
257.comment-avatar img { width: 100%; height: 100%; object-fit: cover; }
258.comment-avatar span {
259 font-family: var(--font-display, serif);
260 font-weight: 700;
261 color: var(--accent);
262}
263
264.comment-body { flex: 1; min-width: 0; }
265.comment-meta {
266 display: flex;
267 gap: 0.5rem;
268 align-items: baseline;
269 font-size: 0.85rem;
270 margin-bottom: 0.3rem;
271}
272.comment-author { color: var(--ink); font-weight: 600; text-decoration: none; }
273.comment-author:hover { color: var(--accent); }
274.comment-time { color: var(--ink-muted, var(--ink-soft)); }
275.comment-content {
276 white-space: pre-wrap;
277 word-wrap: break-word;
278 color: var(--ink);
279 line-height: 1.5;
280 font-size: 0.95rem;
281}
282
283.comment-actions {
284 display: flex;
285 gap: 0.5rem;
286 margin-top: 0.4rem;
287}
288.comment-reply-btn, .comment-delete-btn {
289 background: none;
290 border: 0;
291 color: var(--ink-muted, var(--ink-soft));
292 font-size: 0.8rem;
293 cursor: pointer;
294 padding: 0.2rem 0;
295 font-family: inherit;
296 text-transform: uppercase;
297 letter-spacing: 0.04em;
298}
299.comment-reply-btn:hover { color: var(--accent); }
300.comment-delete-btn:hover { color: #c33; }
301
302.comment-replies {
303 margin-top: 1rem;
304 margin-left: 0;
305 border-left: 2px solid var(--rule);
306 padding-left: 1rem;
307}
308.comment-reply { padding: 0.75rem 0; }
309.comment-replies > .comment-reply:first-child { border-top: 0; padding-top: 0; }
310.comment-reply .comment-avatar { width: 32px; height: 32px; }
311.comment-reply .comment-avatar span { font-size: 0.85rem; }
312
313.comment-form, .comment-reply-form {
314 display: flex;
315 flex-direction: column;
316 gap: 0.6rem;
317 background: var(--paper-2);
318 border: 1px solid var(--rule);
319 border-radius: 8px;
320 padding: 1rem;
321 margin-top: 1rem;
322}
323.comment-form-label { display: flex; flex-direction: column; gap: 0.4rem; }
324.comment-form-label > span { font-size: 0.85rem; color: var(--ink-muted, var(--ink-soft)); }
325.comment-form textarea, .comment-reply-form textarea {
326 width: 100%;
327 resize: vertical;
328 min-height: 70px;
329 padding: 0.65rem 0.85rem;
330 border: 1px solid var(--rule);
331 border-radius: 5px;
332 background: var(--paper);
333 color: var(--ink);
334 font-family: inherit;
335 font-size: 0.95rem;
336 line-height: 1.4;
337 box-sizing: border-box;
338}
339.comment-form button { align-self: flex-start; }
340.comment-reply-form-actions { display: flex; gap: 0.5rem; }
341/* Show the reply form only AFTER clicking REPLY. The display:flex above would
342 otherwise override the [hidden] attribute → form was always open. */
343.comment-reply-form[hidden] { display: none; }
344/* DELETE button is inside a <form>; display:contents makes it a direct flex-sibling
345 of REPLY → pixel-perfect alignment + equal gap. */
346.comment-actions form { display: contents; }
347
348.comments-login-cta { margin-top: 1.5rem; text-align: center; }
349
350/* ─── Related posts (3-card grid above pinned-nav) ─────────────── */
351.post-related {
352 margin: 3rem auto 1.5rem;
353 /* Break out of the 720px article column so the cards have room to breathe.
354 Cap at 1100 to match other wide content. */
355 max-width: 1100px;
356 padding: 0 1rem;
357}
358.post-related-heading {
359 font-family: var(--font-ui, system-ui), sans-serif;
360 font-size: 0.75rem;
361 font-weight: 600;
362 text-transform: uppercase;
363 letter-spacing: 0.15em;
364 color: var(--ink-muted, var(--ink-soft));
365 margin: 0 0 1rem;
366}
367.post-related-grid {
368 list-style: none;
369 padding: 0; margin: 0;
370 display: grid;
371 grid-template-columns: repeat(3, minmax(0, 1fr));
372 gap: 1rem;
373}
374@media (max-width: 880px) { .post-related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
375@media (max-width: 540px) { .post-related-grid { grid-template-columns: 1fr; } }
376
377.post-related-card {
378 background: var(--paper);
379 border: 1px solid var(--rule);
380 border-radius: 10px;
381 overflow: hidden;
382 transition: border-color 150ms, transform 150ms;
383}
384.post-related-card:hover { border-color: var(--accent); transform: translateY(-2px); }
385.post-related-card a {
386 display: block;
387 color: inherit;
388 text-decoration: none;
389}
390.post-related-cover {
391 display: block;
392 aspect-ratio: 16 / 10;
393 background: var(--paper-2) center/cover no-repeat;
394}
395.post-related-cover--empty {
396 background-image: linear-gradient(135deg,
397 color-mix(in srgb, var(--accent) 12%, var(--paper-2)),
398 var(--paper-2));
399}
400.post-related-meta {
401 display: flex; flex-direction: column; gap: 0.4rem;
402 padding: 0.85rem 1rem 1.1rem;
403}
404.post-related-date {
405 font-size: 0.78rem;
406 color: var(--ink-muted, var(--ink-soft));
407 font-variant-numeric: tabular-nums;
408}
409.post-related-title {
410 font-family: var(--font-display, serif);
411 font-size: 1.1rem;
412 font-weight: 600;
413 color: var(--ink);
414 line-height: 1.25;
415}
416
417/* ─── Pinned navigation cards (v9 style) ───────────────────────── */
418.post-pinned-nav {
419 display: grid;
420 grid-template-columns: 1fr 1fr;
421 gap: 1rem;
422 margin: 1.5rem auto 2rem;
423 max-width: 1100px;
424 padding: 0 1rem;
425}
426@media (max-width: 600px) {
427 .post-pinned-nav { grid-template-columns: 1fr; }
428}
429
430.post-pinned-card {
431 display: flex; align-items: center; gap: 1rem;
432 padding: 1rem 1.25rem;
433 border: 1.5px solid color-mix(in srgb, var(--accent) 50%, transparent);
434 background: color-mix(in srgb, var(--accent) 6%, var(--paper));
435 border-radius: 10px;
436 text-decoration: none;
437 color: var(--ink);
438 transition: border-color 150ms, background 150ms, transform 150ms;
439 min-height: 88px;
440}
441.post-pinned-card:hover {
442 border-color: var(--accent);
443 background: color-mix(in srgb, var(--accent) 11%, var(--paper));
444 transform: translateY(-2px);
445}
446.post-pinned-arrow {
447 font-size: 1.6rem;
448 color: var(--accent);
449 flex-shrink: 0;
450 line-height: 1;
451}
452.post-pinned-card--next {
453 /* "Volgende" card aligns text to the right with the arrow on the right
454 side, mirroring v9 — the arrow is on the OPPOSITE end from the body. */
455 flex-direction: row-reverse;
456 text-align: right;
457}
458.post-pinned-body {
459 display: flex; flex-direction: column; gap: 0.25rem;
460 flex: 1; min-width: 0;
461}
462.post-pinned-label {
463 font-family: var(--font-ui, system-ui), sans-serif;
464 font-size: 0.7rem; font-weight: 600;
465 text-transform: uppercase;
466 letter-spacing: 0.1em;
467 color: var(--accent);
468}
469.post-pinned-title {
470 font-family: var(--font-display, serif);
471 font-size: 1.05rem; font-weight: 600;
472 color: var(--ink);
473 line-height: 1.25;
474 overflow: hidden;
475 text-overflow: ellipsis;
476 display: -webkit-box;
477 -webkit-line-clamp: 2;
478 -webkit-box-orient: vertical;
479}
480.post-pinned-cta {
481 font-size: 0.78rem;
482 color: var(--accent);
483 font-weight: 500;
484}
485
486/* Edge-of-stack indicator: dashed border, muted styling. */
487.post-pinned-card--edge {
488 flex-direction: column;
489 align-items: flex-start;
490 justify-content: center;
491 gap: 0.35rem;
492 border-style: dashed;
493 background: transparent;
494 color: var(--ink-muted, var(--ink-soft));
495 cursor: default;
496}
497.post-pinned-card--edge:hover {
498 /* Edge cards aren't clickable — undo the lift effect. */
499 transform: none;
500 border-color: color-mix(in srgb, var(--accent) 50%, transparent);
501 background: transparent;
502}
503.post-pinned-edge-label {
504 font-family: var(--font-ui, system-ui), sans-serif;
505 font-size: 0.72rem;
506 font-weight: 600;
507 text-transform: uppercase;
508 letter-spacing: 0.15em;
509 color: var(--accent);
510}
511.post-pinned-edge-title {
512 font-family: var(--font-display, serif);
513 font-size: 1.05rem;
514 font-weight: 600;
515 color: var(--ink);
516}
517</style>
Note: See TracBrowser for help on using the repository browser.