source: Klonkt/src/routes/hub.js@ 7d932ce

main
Last change on this file since 7d932ce was 834bcc3, checked in by Robin Genis <roboburr@…>, 3 months ago

i18n: translate Dutch code comments to English across src/

Comments in routes/services/views/config/middleware/assets translated to
English for the public repo. A few dev-facing throw/console message strings
were Englished too. No user-facing UI strings or i18n dictionary values changed
(src/services/i18n.js untouched). Logic unchanged.

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

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/**
2 * Hub home page — hub mode only. Instead of rendering the primary Klonkt site,
3 * '/' renders a company overview here: the latest posts from ALL users combined
4 * + a list of the Klonkt sites.
5 *
6 * In solo mode this does nothing (next()) and posts.js renders the single site.
7 */
8
9import express from 'express';
10import db from '../config/database.js';
11import { renderPage } from '../middleware/render.js';
12import { getTenancy, getSetting } from '../services/SettingsService.js';
13
14const router = express.Router();
15
16router.get('/', (req, res, next) => {
17 if (getTenancy() !== 'hub') return next();
18 // If resolveSite addressed a specific site (/user/:slug or /sites/:slug),
19 // req.url was rewritten to '/' — do NOT show the overview but let posts.js
20 // render the site itself. siteUrlBase is set in that case.
21 if (res.locals.siteUrlBase) return next();
22
23 // Latest published posts across all sites.
24 const posts = db.prepare(`
25 SELECT p.title, p.slug, p.excerpt, p.published_at, p.created_at,
26 p.cover_image_url, p.type,
27 s.slug AS site_slug, s.title AS site_title, s.profile_photo AS site_photo,
28 u.username AS author_username
29 FROM posts p
30 JOIN sites s ON s.id = p.site_id
31 LEFT JOIN users u ON u.id = p.author_id
32 WHERE p.status = 'published'
33 ORDER BY COALESCE(p.published_at, p.created_at) DESC
34 LIMIT 24
35 `).all();
36
37 // The main/label site (the explicitly primary = the company/main account) is
38 // NOT an artist; we display it separately at the top, not in the Artists roster.
39 const mainSite = db.prepare(`
40 SELECT s.id, s.slug, s.title, s.tagline, s.profile_photo, s.accent,
41 u.avatar_url AS owner_avatar,
42 (SELECT COUNT(*) FROM posts WHERE site_id = s.id AND status = 'published') AS post_count
43 FROM sites s
44 LEFT JOIN users u ON u.id = s.owner_id
45 WHERE s.is_primary = 1
46 LIMIT 1
47 `).get() || null;
48 const mainId = mainSite ? mainSite.id : '';
49
50 // Featured Klonkt sites for the home roster: most active first (number of
51 // published posts), then newest. Excl. the main site. Capped at
52 // HOME_ROSTER_LIMIT so the home scales — full list is at /leden.
53 const HOME_ROSTER_LIMIT = 24;
54 const artists = db.prepare(`
55 SELECT s.slug, s.title, s.tagline, s.profile_photo, s.accent,
56 u.avatar_url AS owner_avatar,
57 (SELECT COUNT(*) FROM posts WHERE site_id = s.id AND status = 'published') AS post_count
58 FROM sites s
59 LEFT JOIN users u ON u.id = s.owner_id
60 WHERE s.id != @mainId
61 ORDER BY post_count DESC, s.created_at DESC
62 LIMIT @limit
63 `).all({ mainId, limit: HOME_ROSTER_LIMIT });
64 const totalArtists = db.prepare('SELECT COUNT(*) AS c FROM sites WHERE id != ?').get(mainId).c;
65
66 // The hub page is GENERIC (not belonging to any user) — branding comes from global
67 // settings managed by the admin in the admin panel, not from a site.
68 const hub = {
69 title: getSetting('hub_title') || 'Overzicht',
70 tagline: getSetting('hub_tagline') || '',
71 intro: getSetting('hub_intro') || '',
72 heroImage: getSetting('hub_hero_image') || '',
73 heroOverlay: (() => { const v = parseInt(getSetting('hub_hero_overlay'), 10); return Number.isFinite(v) ? Math.max(0, Math.min(100, v)) : 45; })(),
74 };
75
76 renderPage(req, res, 'pages/hub-home', {
77 pageTitle: hub.title,
78 socialDescr: hub.intro || hub.tagline || '',
79 bodyClass: 'on-home on-hub',
80 hub,
81 mainSite,
82 artists,
83 totalArtists,
84 rosterLimit: HOME_ROSTER_LIMIT,
85 posts,
86 });
87});
88
89export default router;
Note: See TracBrowser for help on using the repository browser.