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

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

feat(cirkel): render boosted posts in the pinned style with a Boost badge

A post you boosted (ap_timeline.boosted) now stands out in the Cirkel: same visual
treatment as a pinned post on the solo page (accent outline in grid, badge), but the
badge reads 'Boost' (🔁/loop icon) instead of 'Pinned'. Featured-account posts stay
normal. getCirkelPosts returns t.boosted; circle.js sets isBoost; post-card/post-tile
swap the badge + reuse is-pinned styling. No effect on the home page (isBoost only set
in the Cirkel).

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

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * Circle feed — the artists this site features (auto-boosts), sourced from
3 * ActivityPub. Cards link to the source post. Available whenever the site
4 * auto-boosts at least one account; otherwise next() -> postsRoutes.
5 * GET /cirkel
6 */
7
8import express from 'express';
9import { renderPage } from '../middleware/render.js';
10import { apEnabled } from '../services/SettingsService.js';
11import ActivityPubService from '../services/ActivityPubService.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}
21function mediaImage(media_json) {
22 const media = safeJson(media_json).map((m) => ({ ...m, url: safeUrl(m.url) })).filter((m) => m.url);
23 return media.find((m) => /image/i.test(m.type || '')) || media[0] || null;
24}
25function htmlToText(html) {
26 return String(html || '').replace(/<[^>]+>/g, ' ').replace(/&[a-z#0-9]+;/gi, ' ').replace(/\s+/g, ' ').trim();
27}
28
29router.get('/cirkel', (req, res, next) => {
30 const site = res.locals.site;
31 if (!site || !apEnabled() || (ActivityPubService.autoBoostCount(site.slug) === 0 && ActivityPubService.boostedCount(site.slug) === 0)) return next();
32
33 const posts = ActivityPubService.getCirkelPosts(site.slug, 80).map((r) => {
34 const text = htmlToText(r.content);
35 const image = mediaImage(r.media_json);
36 const name = r.author_name || r.author_handle || 'Onbekend';
37 return {
38 id: 'ap-' + r.id,
39 slug: '',
40 title: text ? (text.length > 90 ? text.slice(0, 90) + '…' : text) : name,
41 excerpt: '',
42 cover_image_url: image ? image.url : null,
43 published_at: r.published,
44 created_at: r.published,
45 type: 'post',
46 tags: '',
47 pinned: 0,
48 isBoost: !!r.boosted, // a post YOU boosted → render in the pinned style with a Boost badge
49 status: 'published',
50 source_name: name,
51 external_url: safeUrl(r.url),
52 };
53 });
54
55 const sites = ActivityPubService.getCirkelMembers(site.slug)
56 .map((s) => ({ name: s.name || 'Onbekend', url: safeUrl(s.url), avatar: safeUrl(s.icon) }));
57
58 renderPage(req, res, 'pages/circle-feed', { pageTitle: 'Cirkel', bodyClass: 'on-cirkel', posts, sites });
59});
60
61export default router;
Note: See TracBrowser for help on using the repository browser.