source: Klonkt/src/views/pages/post.ejs@ 40cf2ef

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

style(activitypub): inline address form for reply-via-fediverse (no browser prompt)

Clicking 'Reply via the fediverse' now opens a styled inline input (handle + go +
cancel) instead of the native prompt() dialog.

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-prompt="<%= t('fedi.remote_prompt') %>">
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" placeholder="@jij@mastodon.social" autocomplete="off" spellcheck="false">'
121 + '<button type="submit" class="btn btn-primary fedi-remote-go">&rarr;</button>'
122 + '<button type="button" class="fedi-remote-cancel" aria-label="x">&times;</button>';
123 b.parentNode.insertBefore(f, b.nextSibling);
124 f.querySelector('input').focus();
125 });
126 document.addEventListener('submit', function(e){
127 var f = e.target.closest && e.target.closest('.fedi-remote-form');
128 if (!f) return;
129 e.preventDefault();
130 go(f.querySelector('input').value, f.dataset.uri);
131 });
132 })();
133 </script>
134
135
136 <%# ── Related posts (3-card grid) ─────────────────────────────
137 Always shown if at least one related post exists. Selection logic
138 lives server-side: same-tag posts ranked by overlap, falling back
139 to most-recent if there's no tag overlap. %>
140 <% if (relatedPosts && relatedPosts.length > 0) { %>
141 <section class="post-related" aria-labelledby="related-heading">
142 <h2 class="post-related-heading" id="related-heading"><%= t('related.title') %></h2>
143 <ul class="post-related-grid">
144 <% relatedPosts.forEach(function(rp) { %>
145 <li class="post-related-card">
146 <a href="<%= rp._urlBase || '' %>/<%= rp.slug %>"<% if (!rp._urlBase) { %>
147 hx-get="/<%= rp.slug %>?partial=1" hx-target="#pcms-main"
148 hx-push-url="/<%= rp.slug %>" hx-indicator="#pcms-loading"<% } %>>
149 <% if (rp.cover_image_url) { %>
150 <span class="post-related-cover"
151 style="background-image: url('<%= rp.cover_image_url %>')"
152 aria-hidden="true"></span>
153 <% } else { %>
154 <span class="post-related-cover post-related-cover--empty" aria-hidden="true"></span>
155 <% } %>
156 <span class="post-related-meta">
157 <span class="post-related-date"><%= formatDate(rp.published_at) %></span>
158 <span class="post-related-title"><%= rp.title %></span>
159 </span>
160 </a>
161 </li>
162 <% }); %>
163 </ul>
164 </section>
165 <% } %>
166
167</article>
168<style>
169.post-page { max-width: 720px; margin: 0.5rem auto 2rem; padding: 0 1rem; }
170.post-cover { margin: 0 0 2rem; border-radius: 8px; overflow: hidden; }
171.post-cover img { width: 100%; height: auto; display: block; }
172.post-header { margin-bottom: 2rem; }
173.post-title { font-family: var(--font-display, serif); font-size: 2.5rem; line-height: 1.1; margin: 0 0 1rem; }
174@media (max-width: 600px) { .post-title { font-size: 1.85rem; } }
175.post-meta { font-size: 0.9rem; color: var(--ink-muted); }
176.author { font-weight: 500; color: var(--ink-soft); text-decoration: none; }
177.author:hover { color: var(--accent); }
178.post-content { font-family: var(--font-body, serif); font-size: 1.1rem; line-height: 1.7; color: var(--ink); }
179.post-content p { margin: 1.2em 0; }
180.post-like-row { margin-top: 1rem; }
181.like-btn {
182 display: inline-flex; align-items: center; gap: 0.45rem;
183 padding: 0.4rem 0.85rem; border: 1px solid var(--rule); border-radius: 999px;
184 background: var(--paper-2); color: var(--ink); font: inherit; font-size: 0.95rem;
185 cursor: pointer; text-decoration: none; transition: border-color 120ms, color 120ms, background 120ms;
186}
187.like-btn:hover { border-color: var(--accent); }
188.like-btn .like-heart { font-size: 1.1rem; line-height: 1; }
189.like-btn.is-liked { border-color: var(--accent); color: var(--accent); }
190.like-btn.is-liked .like-heart { color: var(--accent); }
191.like-btn .like-count { font-variant-numeric: tabular-nums; }
192.post-content h2 { font-family: var(--font-display, serif); font-size: 1.6rem; margin: 2rem 0 1rem; }
193.post-content h3 { font-family: var(--font-display, serif); font-size: 1.3rem; margin: 1.5rem 0 0.75rem; }
194.post-content a { color: var(--accent); }
195.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; }
196.post-content pre { background: var(--paper-2); padding: 1rem; border-radius: 6px; overflow-x: auto; }
197.post-content blockquote { border-left: 3px solid var(--accent); padding-left: 1rem; margin: 1.5rem 0; color: var(--ink-soft); font-style: italic; }
198.post-content img { max-width: 100%; height: auto; border-radius: 6px; }
199.post-tags { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 2rem 0; }
200.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; }
201.tag:hover { background: var(--accent); color: white; }
202.post-actions { display: flex; gap: 0.5rem; margin: 2rem 0; padding: 1rem; background: var(--paper-2); border-radius: 6px; flex-wrap: wrap; }
203
204/* ============================================================
205 Comments
206 ============================================================ */
207.post-comments {
208 margin-top: 3rem;
209 padding-top: 2rem;
210 border-top: 1px solid var(--rule);
211}
212.comments-heading {
213 font-family: var(--font-display, serif);
214 font-size: 1.5rem;
215 margin: 0 0 1.5rem;
216}
217.comments-empty { color: var(--ink-muted, var(--ink-soft)); margin: 0 0 1.5rem; }
218.comments-pending-flash {
219 background: rgba(40, 160, 90, 0.15);
220 color: #2a9d5e;
221 border: 1px solid rgba(40, 160, 90, 0.3);
222 padding: 0.75rem 1rem;
223 border-radius: 6px;
224 margin-bottom: 1rem;
225 font-size: 0.9rem;
226}
227.comments-empty a { color: var(--accent); }
228
229.comments-list, .comment-replies {
230 list-style: none;
231 padding: 0;
232 margin: 0 0 2rem;
233}
234
235.comment {
236 display: flex;
237 gap: 0.85rem;
238 padding: 1rem 0;
239 border-top: 1px solid var(--rule);
240}
241.comments-list > .comment:first-child { border-top: 0; padding-top: 0; }
242
243.comment-avatar {
244 flex-shrink: 0;
245 width: 40px;
246 height: 40px;
247 border-radius: 50%;
248 background: var(--paper-2);
249 border: 1px solid var(--rule);
250 overflow: hidden;
251 display: inline-flex;
252 align-items: center;
253 justify-content: center;
254}
255.comment-avatar img { width: 100%; height: 100%; object-fit: cover; }
256.comment-avatar span {
257 font-family: var(--font-display, serif);
258 font-weight: 700;
259 color: var(--accent);
260}
261
262.comment-body { flex: 1; min-width: 0; }
263.comment-meta {
264 display: flex;
265 gap: 0.5rem;
266 align-items: baseline;
267 font-size: 0.85rem;
268 margin-bottom: 0.3rem;
269}
270.comment-author { color: var(--ink); font-weight: 600; text-decoration: none; }
271.comment-author:hover { color: var(--accent); }
272.comment-time { color: var(--ink-muted, var(--ink-soft)); }
273.comment-content {
274 white-space: pre-wrap;
275 word-wrap: break-word;
276 color: var(--ink);
277 line-height: 1.5;
278 font-size: 0.95rem;
279}
280
281.comment-actions {
282 display: flex;
283 gap: 0.5rem;
284 margin-top: 0.4rem;
285}
286.comment-reply-btn, .comment-delete-btn {
287 background: none;
288 border: 0;
289 color: var(--ink-muted, var(--ink-soft));
290 font-size: 0.8rem;
291 cursor: pointer;
292 padding: 0.2rem 0;
293 font-family: inherit;
294 text-transform: uppercase;
295 letter-spacing: 0.04em;
296}
297.comment-reply-btn:hover { color: var(--accent); }
298.comment-delete-btn:hover { color: #c33; }
299
300.comment-replies {
301 margin-top: 1rem;
302 margin-left: 0;
303 border-left: 2px solid var(--rule);
304 padding-left: 1rem;
305}
306.comment-reply { padding: 0.75rem 0; }
307.comment-replies > .comment-reply:first-child { border-top: 0; padding-top: 0; }
308.comment-reply .comment-avatar { width: 32px; height: 32px; }
309.comment-reply .comment-avatar span { font-size: 0.85rem; }
310
311.comment-form, .comment-reply-form {
312 display: flex;
313 flex-direction: column;
314 gap: 0.6rem;
315 background: var(--paper-2);
316 border: 1px solid var(--rule);
317 border-radius: 8px;
318 padding: 1rem;
319 margin-top: 1rem;
320}
321.comment-form-label { display: flex; flex-direction: column; gap: 0.4rem; }
322.comment-form-label > span { font-size: 0.85rem; color: var(--ink-muted, var(--ink-soft)); }
323.comment-form textarea, .comment-reply-form textarea {
324 width: 100%;
325 resize: vertical;
326 min-height: 70px;
327 padding: 0.65rem 0.85rem;
328 border: 1px solid var(--rule);
329 border-radius: 5px;
330 background: var(--paper);
331 color: var(--ink);
332 font-family: inherit;
333 font-size: 0.95rem;
334 line-height: 1.4;
335 box-sizing: border-box;
336}
337.comment-form button { align-self: flex-start; }
338.comment-reply-form-actions { display: flex; gap: 0.5rem; }
339/* Show the reply form only AFTER clicking REPLY. The display:flex above would
340 otherwise override the [hidden] attribute → form was always open. */
341.comment-reply-form[hidden] { display: none; }
342/* DELETE button is inside a <form>; display:contents makes it a direct flex-sibling
343 of REPLY → pixel-perfect alignment + equal gap. */
344.comment-actions form { display: contents; }
345
346.comments-login-cta { margin-top: 1.5rem; text-align: center; }
347
348/* ─── Related posts (3-card grid above pinned-nav) ─────────────── */
349.post-related {
350 margin: 3rem auto 1.5rem;
351 /* Break out of the 720px article column so the cards have room to breathe.
352 Cap at 1100 to match other wide content. */
353 max-width: 1100px;
354 padding: 0 1rem;
355}
356.post-related-heading {
357 font-family: var(--font-ui, system-ui), sans-serif;
358 font-size: 0.75rem;
359 font-weight: 600;
360 text-transform: uppercase;
361 letter-spacing: 0.15em;
362 color: var(--ink-muted, var(--ink-soft));
363 margin: 0 0 1rem;
364}
365.post-related-grid {
366 list-style: none;
367 padding: 0; margin: 0;
368 display: grid;
369 grid-template-columns: repeat(3, minmax(0, 1fr));
370 gap: 1rem;
371}
372@media (max-width: 880px) { .post-related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
373@media (max-width: 540px) { .post-related-grid { grid-template-columns: 1fr; } }
374
375.post-related-card {
376 background: var(--paper);
377 border: 1px solid var(--rule);
378 border-radius: 10px;
379 overflow: hidden;
380 transition: border-color 150ms, transform 150ms;
381}
382.post-related-card:hover { border-color: var(--accent); transform: translateY(-2px); }
383.post-related-card a {
384 display: block;
385 color: inherit;
386 text-decoration: none;
387}
388.post-related-cover {
389 display: block;
390 aspect-ratio: 16 / 10;
391 background: var(--paper-2) center/cover no-repeat;
392}
393.post-related-cover--empty {
394 background-image: linear-gradient(135deg,
395 color-mix(in srgb, var(--accent) 12%, var(--paper-2)),
396 var(--paper-2));
397}
398.post-related-meta {
399 display: flex; flex-direction: column; gap: 0.4rem;
400 padding: 0.85rem 1rem 1.1rem;
401}
402.post-related-date {
403 font-size: 0.78rem;
404 color: var(--ink-muted, var(--ink-soft));
405 font-variant-numeric: tabular-nums;
406}
407.post-related-title {
408 font-family: var(--font-display, serif);
409 font-size: 1.1rem;
410 font-weight: 600;
411 color: var(--ink);
412 line-height: 1.25;
413}
414
415/* ─── Pinned navigation cards (v9 style) ───────────────────────── */
416.post-pinned-nav {
417 display: grid;
418 grid-template-columns: 1fr 1fr;
419 gap: 1rem;
420 margin: 1.5rem auto 2rem;
421 max-width: 1100px;
422 padding: 0 1rem;
423}
424@media (max-width: 600px) {
425 .post-pinned-nav { grid-template-columns: 1fr; }
426}
427
428.post-pinned-card {
429 display: flex; align-items: center; gap: 1rem;
430 padding: 1rem 1.25rem;
431 border: 1.5px solid color-mix(in srgb, var(--accent) 50%, transparent);
432 background: color-mix(in srgb, var(--accent) 6%, var(--paper));
433 border-radius: 10px;
434 text-decoration: none;
435 color: var(--ink);
436 transition: border-color 150ms, background 150ms, transform 150ms;
437 min-height: 88px;
438}
439.post-pinned-card:hover {
440 border-color: var(--accent);
441 background: color-mix(in srgb, var(--accent) 11%, var(--paper));
442 transform: translateY(-2px);
443}
444.post-pinned-arrow {
445 font-size: 1.6rem;
446 color: var(--accent);
447 flex-shrink: 0;
448 line-height: 1;
449}
450.post-pinned-card--next {
451 /* "Volgende" card aligns text to the right with the arrow on the right
452 side, mirroring v9 — the arrow is on the OPPOSITE end from the body. */
453 flex-direction: row-reverse;
454 text-align: right;
455}
456.post-pinned-body {
457 display: flex; flex-direction: column; gap: 0.25rem;
458 flex: 1; min-width: 0;
459}
460.post-pinned-label {
461 font-family: var(--font-ui, system-ui), sans-serif;
462 font-size: 0.7rem; font-weight: 600;
463 text-transform: uppercase;
464 letter-spacing: 0.1em;
465 color: var(--accent);
466}
467.post-pinned-title {
468 font-family: var(--font-display, serif);
469 font-size: 1.05rem; font-weight: 600;
470 color: var(--ink);
471 line-height: 1.25;
472 overflow: hidden;
473 text-overflow: ellipsis;
474 display: -webkit-box;
475 -webkit-line-clamp: 2;
476 -webkit-box-orient: vertical;
477}
478.post-pinned-cta {
479 font-size: 0.78rem;
480 color: var(--accent);
481 font-weight: 500;
482}
483
484/* Edge-of-stack indicator: dashed border, muted styling. */
485.post-pinned-card--edge {
486 flex-direction: column;
487 align-items: flex-start;
488 justify-content: center;
489 gap: 0.35rem;
490 border-style: dashed;
491 background: transparent;
492 color: var(--ink-muted, var(--ink-soft));
493 cursor: default;
494}
495.post-pinned-card--edge:hover {
496 /* Edge cards aren't clickable — undo the lift effect. */
497 transform: none;
498 border-color: color-mix(in srgb, var(--accent) 50%, transparent);
499 background: transparent;
500}
501.post-pinned-edge-label {
502 font-family: var(--font-ui, system-ui), sans-serif;
503 font-size: 0.72rem;
504 font-weight: 600;
505 text-transform: uppercase;
506 letter-spacing: 0.15em;
507 color: var(--accent);
508}
509.post-pinned-edge-title {
510 font-family: var(--font-display, serif);
511 font-size: 1.05rem;
512 font-weight: 600;
513 color: var(--ink);
514}
515</style>
Note: See TracBrowser for help on using the repository browser.