Changeset 72ec6a4 in Klonkt for src/routes/posts.js
- Timestamp:
- 07/31/2026 06:55:59 PM (6 weeks ago)
- Branches:
- main
- Children:
- 17546af
- Parents:
- bfa6fa1
- File:
-
- 1 edited
-
src/routes/posts.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/posts.js
rbfa6fa1 r72ec6a4 763 763 } 764 764 765 function postNeighbors(site, post, isHub) { 766 const urlBaseFor = (p) => (isHub && p && p.site_slug) ? `/user/${p.site_slug}` : ''; 767 const ordered = isHub 768 ? db.prepare(` 769 SELECT p.id, p.slug, p.title, p.pinned, s.slug AS site_slug 770 FROM posts p JOIN sites s ON s.id = p.site_id 771 WHERE p.status = 'published' 772 ORDER BY p.published_at DESC 773 `).all() 774 : db.prepare(` 775 SELECT id, slug, title, pinned FROM posts 776 WHERE site_id = ? AND status = 'published' 777 ORDER BY (pinned = 0) ASC, pinned ASC, published_at DESC 778 `).all(site.id); 765 function postNeighbors(site, post) { 766 const ordered = db.prepare(` 767 SELECT id, slug, title, pinned FROM posts 768 WHERE site_id = ? AND status = 'published' 769 ORDER BY (pinned = 0) ASC, pinned ASC, published_at DESC 770 `).all(site.id); 779 771 const idx = ordered.findIndex((p) => p.id === post.id); 780 772 const newerPost = idx > 0 ? ordered[idx - 1] : null; 781 773 const olderPost = (idx >= 0 && idx < ordered.length - 1) ? ordered[idx + 1] : null; 782 if (newerPost) newerPost._urlBase = urlBaseFor(newerPost);783 if (olderPost) olderPost._urlBase = urlBaseFor(olderPost);774 if (newerPost) newerPost._urlBase = ''; 775 if (olderPost) olderPost._urlBase = ''; 784 776 return { newerPost, olderPost }; 785 777 } … … 1344 1336 const _unlocked = _u && _u.purpose === 'unlocked' && _u.siteId === site.id && String(_u.post) === String(post.slug); 1345 1337 if (post.paid && !canEditThis && !_unlocked) { 1346 const { newerPost, olderPost } = postNeighbors(site, post , res.locals.tenancy === 'hub');1338 const { newerPost, olderPost } = postNeighbors(site, post); 1347 1339 return renderPage(req, res, 'pages/paid-gate', { 1348 1340 pageTitle: post.title || 'Voor supporters', … … 1364 1356 // Same Newer/Older navigation as on a normal post, so the visitor doesn't get 1365 1357 // stuck on the fan gate but can keep browsing. 1366 const { newerPost, olderPost } = postNeighbors(site, post , res.locals.tenancy === 'hub');1358 const { newerPost, olderPost } = postNeighbors(site, post); 1367 1359 return renderPage(req, res, 'pages/fan-gate', { 1368 1360 pageTitle: post.title || 'Alleen voor fans', … … 1396 1388 // Prev / next chronological (kept for back-compat — "post-nav" feature 1397 1389 // below the article still uses these as a simple linear navigation). 1398 // Hub mode: Related posts + Newer/Older pull from ALL users (all sites), 1399 // newest first. Solo mode: within the current site (old behaviour). 1400 const isHub = res.locals.tenancy === 'hub'; 1401 // Per-post URL base: in hub a link points to /user/<site-slug>/<post-slug>. 1402 const urlBaseFor = (p) => (isHub && p && p.site_slug) ? `/user/${p.site_slug}` : ''; 1390 const urlBaseFor = () => ''; 1403 1391 1404 1392 // Newer/Older across ALL posts (shared helper — also used by the fan gate). 1405 const { newerPost, olderPost } = postNeighbors(site, post , isHub);1393 const { newerPost, olderPost } = postNeighbors(site, post); 1406 1394 1407 1395 // ── Related posts: same-tag matching with recency fallback ───── 1408 1396 // Fetch ~50 candidates, score by tag overlap, take top 3. 1409 1397 // Excluding self via `id != ?`. 1410 const candidates = isHub 1411 ? db.prepare(` 1412 SELECT p.id, p.slug, p.title, p.cover_image_url, p.cover_video_url, p.published_at, p.tags, p.nsfw, p.content_warning, s.slug AS site_slug 1413 FROM posts p JOIN sites s ON s.id = p.site_id 1414 WHERE p.status = 'published' AND p.id != ? 1415 ORDER BY p.published_at DESC LIMIT 50 1416 `).all(post.id) 1417 : db.prepare(` 1418 SELECT id, slug, title, cover_image_url, cover_video_url, published_at, tags, nsfw, content_warning 1419 FROM posts 1420 WHERE site_id = ? AND status = 'published' AND id != ? 1421 ORDER BY published_at DESC LIMIT 50 1422 `).all(site.id, post.id); 1398 const candidates = db.prepare(` 1399 SELECT id, slug, title, cover_image_url, cover_video_url, published_at, tags, nsfw, content_warning 1400 FROM posts 1401 WHERE site_id = ? AND status = 'published' AND id != ? 1402 ORDER BY published_at DESC LIMIT 50 1403 `).all(site.id, post.id); 1423 1404 1424 1405 // Parse tags JSON safely; missing/malformed → empty array.
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)