source: Klonkt/src/routes/hub.js@ 4d7443b

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

hub: home page redesigned as a label landing page

Separate landing instead of a list: hero (company site title + tagline + bio),
"Artists" roster (all sites except the company site, as avatar cards), and a
"Latest posts" feed across all artists. routes/hub.js now separates company
(primary) from artists (other sites).

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

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * Hub-hoofdpagina — alleen in hub-modus. In plaats van de primaire PrutFolio te
3 * tonen, rendert '/' hier een bedrijfs-overview: de laatste posts van ALLE
4 * gebruikers samengevat + een lijst van de PrutFolio's.
5 *
6 * In solo-modus doet dit niets (next()) en rendert posts.js de enige site.
7 */
8
9import express from 'express';
10import db from '../config/database.js';
11import { renderPage } from '../middleware/render.js';
12import { getTenancy } from '../services/SettingsService.js';
13
14const router = express.Router();
15
16router.get('/', (req, res, next) => {
17 if (getTenancy() !== 'hub') return next();
18
19 // Laatste gepubliceerde posts over álle sites heen.
20 const posts = db.prepare(`
21 SELECT p.title, p.slug, p.excerpt, p.published_at, p.created_at,
22 p.cover_image_url, p.type,
23 s.slug AS site_slug, s.title AS site_title, s.profile_photo AS site_photo,
24 u.username AS author_username
25 FROM posts p
26 JOIN sites s ON s.id = p.site_id
27 LEFT JOIN users u ON u.id = p.author_id
28 WHERE p.status = 'published'
29 ORDER BY COALESCE(p.published_at, p.created_at) DESC
30 LIMIT 24
31 `).all();
32
33 // De PrutFolio's (sites) voor de gebruikers-lijst.
34 const sites = db.prepare(`
35 SELECT s.slug, s.title, s.profile_photo,
36 u.username AS owner_username,
37 (SELECT COUNT(*) FROM posts WHERE site_id = s.id AND status = 'published') AS post_count
38 FROM sites s
39 LEFT JOIN users u ON u.id = s.owner_id
40 ORDER BY s.created_at ASC
41 `).all();
42
43 // De primaire/oudste site geldt als de bedrijfssite (label). De roster toont
44 // alleen de artiesten (alle overige sites), niet de bedrijfssite zelf.
45 const company = res.locals.site || null;
46 const artists = company ? sites.filter((s) => s.slug !== company.slug) : sites;
47
48 renderPage(req, res, 'pages/hub-home', {
49 pageTitle: company ? company.title : 'Overzicht',
50 socialDescr: (company && (company.description || company.tagline)) || '',
51 bodyClass: 'on-home on-hub',
52 company,
53 artists,
54 posts,
55 });
56});
57
58export default router;
Note: See TracBrowser for help on using the repository browser.