source: Klonkt/src/routes/admin-seo.js@ d3b9f68

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

fix(i18n): translate admin page titles (pageTitleKey instead of hardcoded strings)

Admin page/tab titles were hardcoded (mostly Dutch: Beheer, Instellingen, Nieuwsbrief, …).
renderPage now accepts pageTitleKey (+ pageTitleVars) and translates it with the resolved
language; the 16 admin routes pass keys. Adds admin.t_* keys in nl/en/de.

  • middleware/render.js — pageTitleKey support
  • services/i18n.js — admin.t_* title keys (nl/en/de)
  • routes/admin*.js — pageTitle string -> pageTitleKey
  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[6623453]1/**
[834bcc3]2 * Admin: advanced SEO settings for the primary site.
[6623453]3 *
[834bcc3]4 * GET /admin/seo -> form with all SEO/social fields for the main site
5 * POST /admin/seo -> save (god-only)
[6623453]6 *
[834bcc3]7 * These fields are already consumed by the <head> (shell.ejs) and the JSON-LD/
8 * OpenGraph tags, but were previously not editable anywhere. The basic
9 * fields (title/bio/robots) remain in Appearance; this is the advanced layer:
10 * title template, canonical, social share image, verification metas,
11 * publisher/JSON-LD and OpenGraph locale.
[6623453]12 *
[834bcc3]13 * Operates on the PRIMARY site (solo = the only site; hub = the company site).
[6623453]14 */
15
16import express from 'express';
17import db from '../config/database.js';
18import { renderPage } from '../middleware/render.js';
19import { requireGod } from '../middleware/auth.js';
20import { getPrimarySite } from '../middleware/site.js';
21
22const router = express.Router();
23
24function trimOrNull(v, max) {
25 const s = (v == null ? '' : String(v)).trim();
26 return s ? s.slice(0, max) : null;
27}
28
29// ==================== FORM ====================
30router.get('/', requireGod, (req, res) => {
31 const primary = getPrimarySite();
32 if (!primary) {
33 return res.redirect('/admin/sites/new?error=' + encodeURIComponent('Maak eerst een site aan'));
34 }
35 const site = db.prepare('SELECT * FROM sites WHERE id = ?').get(primary.id);
36
37 renderPage(req, res, 'pages/admin-seo', {
[3487567]38 pageTitleKey: 'admin.t_seo',
[6623453]39 bodyClass: 'on-admin',
40 site,
41 success: req.query.success || null,
42 error: req.query.error || null,
43 });
44});
45
46// ==================== SAVE ====================
47router.post('/', requireGod, (req, res) => {
48 const primary = getPrimarySite();
49 if (!primary) return res.redirect('/admin/seo?error=' + encodeURIComponent('Geen site gevonden'));
50
51 const f = req.body;
52 const schemaType = f.schema_type === 'Organization' ? 'Organization' : 'Person';
53
54 db.prepare(`
55 UPDATE sites SET
56 robots_index = ?,
57 title_template = ?,
58 canonical = ?,
59 default_description = ?,
60 og_image_default = ?,
61 og_locale = ?,
62 author = ?,
63 twitter = ?,
64 facebook_app_id = ?,
65 google_verification = ?,
66 bing_verification = ?,
67 pinterest_verification = ?,
68 yandex_verification = ?,
69 schema_type = ?,
70 publisher_name = ?,
71 publisher_url = ?,
72 publisher_logo = ?,
73 updated_at = CURRENT_TIMESTAMP
74 WHERE id = ?
75 `).run(
76 f.robots_index ? 1 : 0,
77 (f.title_template || '{title} — {site}').slice(0, 200),
78 trimOrNull(f.canonical, 200),
79 trimOrNull(f.default_description, 500),
80 trimOrNull(f.og_image_default, 500),
81 trimOrNull(f.og_locale, 32),
82 trimOrNull(f.author, 120),
83 trimOrNull(f.twitter, 64),
84 trimOrNull(f.facebook_app_id, 64),
85 trimOrNull(f.google_verification, 200),
86 trimOrNull(f.bing_verification, 200),
87 trimOrNull(f.pinterest_verification, 200),
88 trimOrNull(f.yandex_verification, 200),
89 schemaType,
90 trimOrNull(f.publisher_name, 200),
91 trimOrNull(f.publisher_url, 200),
92 trimOrNull(f.publisher_logo, 500),
93 primary.id,
94 );
95
96 res.redirect('/admin/seo?success=' + encodeURIComponent('SEO-instellingen opgeslagen'));
97});
98
99export default router;
Note: See TracBrowser for help on using the repository browser.