source: Klonkt/src/routes/circle.js@ b960185

main
Last change on this file since b960185 was 43dbf9c, checked in by roboburr <roboburr@…>, 3 months ago

Circles: /cirkel uses the home view (timeline + grid + switcher)

  • post-card/post-tile external-aware: post.external_url -> external link (target=_blank, no htmx) instead of local /slug. Additive; normal posts unchanged. post-card shows 'via <source>' when external.
  • circle.js maps remote_posts to the local post shape + bodyClass on-cirkel.
  • circle-feed.ejs: feed-timeline (.post-list) + feed-grid (.grid-tiles), same classes as home -> the view-switcher works. shell: on-cirkel = feed-page.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 * Publieke Cirkel-feed: /cirkel
3 * Toont de gecachte publieke posts uit je cirkel als statische kaarten.
4 * Alleen actief als tenancy === 'circle' (anders next() -> postsRoutes/404).
5 * Zie docs/cirkels-v1-spec.md §5c.
6 */
7
8import express from 'express';
9import { renderPage } from '../middleware/render.js';
10import db from '../config/database.js';
11import { getTenancy } from '../services/SettingsService.js';
12
13const router = express.Router();
14
15function safeUrl(u) {
16 return typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null;
17}
18function safeJson(s) {
19 try { return s ? JSON.parse(s) : []; } catch { return []; }
20}
21
22router.get('/cirkel', (req, res, next) => {
23 if (getTenancy() !== 'circle') return next();
24
25 const rows = db.prepare(`
26 SELECT p.id, p.published, p.title, p.summary, p.url, p.media_json,
27 a.name AS actor_name, a.url AS actor_url, a.avatar AS actor_avatar
28 FROM remote_posts p
29 JOIN remote_actors a ON a.id = p.actor_id
30 ORDER BY COALESCE(p.published, p.fetched_at) DESC
31 LIMIT 100
32 `).all();
33
34 const posts = rows.map((r) => {
35 const media = safeJson(r.media_json)
36 .map((m) => ({ ...m, url: safeUrl(m.url) }))
37 .filter((m) => m.url);
38 const image = media.find((m) => m.type === 'image') || null;
39 // Vorm de remote-post naar het lokale post-shape zodat post-card/post-tile
40 // (dezelfde timeline/grid-view als de home) 'm renderen. external_url maakt
41 // de partials extern-linkend (naar de bron) i.p.v. lokaal/htmx.
42 return {
43 id: r.id,
44 slug: encodeURIComponent(r.id),
45 title: r.title || '(zonder titel)',
46 excerpt: r.summary || '',
47 cover_image_url: image ? image.url : null,
48 published_at: r.published,
49 created_at: r.published,
50 type: 'post',
51 tags: '',
52 pinned: 0,
53 status: 'published',
54 external_url: safeUrl(r.url),
55 source_name: r.actor_name || 'Onbekend',
56 source_url: safeUrl(r.actor_url),
57 };
58 });
59
60 renderPage(req, res, 'pages/circle-feed', { pageTitle: 'Cirkel', bodyClass: 'on-cirkel', posts });
61});
62
63export default router;
Note: See TracBrowser for help on using the repository browser.