source: Klonkt/src/views/pages/post.ejs@ 59f0170

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

refactor(comments): remove native comments — social is fediverse-only

Removes routes/comments.js + admin-comments.js (+ mounts), the comment section &
reply UI on posts, comment loading in the post route, the admin moderation page +
links, and the per-site comment-moderation settings. The 'From the fediverse'
section is now the post's comment area. The .comment CSS stays (reused there);
the comments table is left in place (dead) so old-data cascade-deletes still work.

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

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