| 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 |
|
|---|
| 8 | import express from 'express';
|
|---|
| 9 | import db from '../config/database.js';
|
|---|
| 10 | import { renderPage } from '../middleware/render.js';
|
|---|
| 11 |
|
|---|
| 12 | const router = express.Router();
|
|---|
| 13 | const VALID_TYPES = new Set(['post', 'foto', 'video', 'audio']);
|
|---|
| 14 |
|
|---|
| 15 | router.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, p.cover_video_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 |
|
|---|
| 39 | export default router;
|
|---|