source: Klonkt/src/routes/types.js@ 7bc636b

main
Last change on this file since 7bc636b was 7bc636b, checked in by Robin <robin@…>, 4 months ago

Initial commit — PrutFolio v1 source (pulled from Hetzner /srv/prutfolio)

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * GET /type/:type
3 *
4 * Lists published posts on the current site filtered by post.type.
5 * Mirrors the v9 /type/ pages (foto, video, audio, post).
6 */
7
8import express from 'express';
9import db from '../config/database.js';
10import { renderPage } from '../middleware/render.js';
11
12const router = express.Router();
13const VALID_TYPES = new Set(['post', 'foto', 'video', 'audio']);
14
15router.get('/:type', (req, res) => {
16 const site = res.locals.site;
17 if (!site) return res.status(404).send('No site');
18
19 const type = (req.params.type || '').toLowerCase().trim();
20 if (!VALID_TYPES.has(type)) return res.status(404).send('Unknown type');
21
22 const posts = db.prepare(`
23 SELECT p.id, p.slug, p.title, p.excerpt, p.cover_image_url,
24 p.published_at, p.type, u.username AS author_username
25 FROM posts p JOIN users u ON u.id = p.author_id
26 WHERE p.site_id = ? AND p.status = 'published' AND p.type = ?
27 ORDER BY p.published_at DESC
28 LIMIT 100
29 `).all(site.id, type);
30
31 renderPage(req, res, 'pages/type', {
32 pageTitle: type[0].toUpperCase() + type.slice(1) + ' — ' + site.title,
33 bodyClass: 'on-special',
34 type,
35 posts,
36 });
37});
38
39export default router;
Note: See TracBrowser for help on using the repository browser.