Voeg Api.AndreaSlopFotografie toe met setup-token, proxy-bewuste limiters en ASF-admin-thema
- Core: opt-in ForwardedHeaders:KnownProxies en rate limiters per clientadres (zonder configuratie ongewijzigd gedrag) - Identity: optioneel setup-token (X-Setup-Token), beide setup-endpoints onder de login-limiter, beveiligingsgebeurtenis setup_token_rejected (5007) - Nieuw client-project SlpModularCms.Api.AndreaSlopFotografie (Identity + Availability) met bijbehorende tests - Frontend: thema asf (VITE_THEME), VITE_DEFAULT_LANGUAGE, tokenveld op de setup-pagina - CI: jobs publish/deploy-asf-test achter ASF_TEST_DEPLOY_ENABLED - Fix U1: 301-Location wordt nu percent-encoded (gevonden door de property-test) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="ASF">
|
||||
<rect width="64" height="64" rx="8" fill="#5f6a58"/>
|
||||
<text x="32" y="41" text-anchor="middle" font-family="Georgia, 'Times New Roman', serif" font-size="26" fill="#faf7f2">ASF</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 283 B |
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Theme "asf" - Andrea Slop Fotografie.
|
||||
*
|
||||
* Re-declares the admin design tokens only (colours, radius, fonts); no layout or component changes.
|
||||
* Colours are exactly those of the Andrea Slop Fotografie website (decision Q5 = B): no contrast
|
||||
* adjustment was made, so a few pairs may fall below WCAG AA - see the hand-back note.
|
||||
*
|
||||
* Fonts are self-hosted through the @fontsource packages (the admin CSP is font-src 'self').
|
||||
* Selected at build time with VITE_THEME=asf.
|
||||
*/
|
||||
@import '@fontsource/jost/latin-400.css';
|
||||
@import '@fontsource/jost/latin-500.css';
|
||||
@import '@fontsource/jost/latin-600.css';
|
||||
@import '@fontsource/marcellus/latin-400.css';
|
||||
|
||||
:root {
|
||||
/* Website palette */
|
||||
--asf-paper: #faf7f2;
|
||||
--asf-paper-2: #f1ebe2;
|
||||
--asf-paper-3: #e8e0d5;
|
||||
--asf-ink: #232120;
|
||||
--asf-ink-2: #55504b;
|
||||
--asf-ink-3: #8a827a;
|
||||
--asf-line: #e2dad0;
|
||||
--asf-accent: #7f8b76;
|
||||
--asf-accent-deep: #5f6a58;
|
||||
--asf-accent-deeper: #475042;
|
||||
--asf-sand: #d9cdbc;
|
||||
--asf-error: #a4443a;
|
||||
|
||||
--asf-font-heading: 'Marcellus', Georgia, 'Times New Roman', serif;
|
||||
--asf-font-body: 'Jost', system-ui, 'Segoe UI', Roboto, sans-serif;
|
||||
|
||||
--background: var(--asf-paper);
|
||||
--foreground: var(--asf-ink);
|
||||
|
||||
--card: var(--asf-paper-2);
|
||||
--card-foreground: var(--asf-ink);
|
||||
|
||||
--popover: var(--asf-paper-2);
|
||||
--popover-foreground: var(--asf-ink);
|
||||
|
||||
--primary: var(--asf-accent-deep);
|
||||
--primary-foreground: var(--asf-paper);
|
||||
|
||||
--secondary: var(--asf-paper-2);
|
||||
--secondary-foreground: var(--asf-ink);
|
||||
|
||||
--muted: var(--asf-paper-2);
|
||||
--muted-foreground: var(--asf-ink-2);
|
||||
|
||||
--accent: var(--asf-paper-3);
|
||||
--accent-foreground: var(--asf-accent-deeper);
|
||||
|
||||
--destructive: var(--asf-error);
|
||||
--destructive-foreground: var(--asf-paper);
|
||||
|
||||
--border: var(--asf-line);
|
||||
--input: var(--asf-line);
|
||||
--ring: var(--asf-accent-deep);
|
||||
|
||||
--radius: 0.25rem;
|
||||
|
||||
--font-sans: var(--asf-font-body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dark mode: the website has no dark variant, so these values are derived from its palette (ink as
|
||||
* background, paper as text, a slightly lighter accent #8a9681 so button text stays above 4.5:1).
|
||||
*/
|
||||
.dark {
|
||||
--background: var(--asf-ink);
|
||||
--foreground: var(--asf-paper);
|
||||
|
||||
--card: #2d2a28;
|
||||
--card-foreground: var(--asf-paper);
|
||||
|
||||
--popover: #2d2a28;
|
||||
--popover-foreground: var(--asf-paper);
|
||||
|
||||
--primary: #8a9681;
|
||||
--primary-foreground: var(--asf-ink);
|
||||
|
||||
--secondary: #353130;
|
||||
--secondary-foreground: var(--asf-paper);
|
||||
|
||||
--muted: #353130;
|
||||
--muted-foreground: var(--asf-sand);
|
||||
|
||||
--accent: #353130;
|
||||
--accent-foreground: var(--asf-paper-3);
|
||||
|
||||
--destructive: #d9776b;
|
||||
--destructive-foreground: var(--asf-ink);
|
||||
|
||||
--border: #433e3b;
|
||||
--input: #433e3b;
|
||||
--ring: #8a9681;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--asf-font-body);
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
[data-slot='card-title'],
|
||||
[data-slot='dialog-title'] {
|
||||
font-family: var(--asf-font-heading);
|
||||
font-weight: 400;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/* Intentionally empty: used when VITE_THEME is unset, so the admin keeps its default look. */
|
||||
@@ -0,0 +1,73 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { availableThemes, resolveTheme } from './resolveTheme';
|
||||
|
||||
describe('resolveTheme', () => {
|
||||
it.each([undefined, '', ' '])('maps %j to the empty module (the default admin)', (name) => {
|
||||
const theme = resolveTheme(name);
|
||||
|
||||
expect(path.basename(theme.css)).toBe('none.css');
|
||||
expect(theme.favicon).toBeNull();
|
||||
expect(fs.readFileSync(theme.css, 'utf-8')).not.toMatch(/--[a-z-]+\s*:/);
|
||||
});
|
||||
|
||||
it('resolves the asf theme with its stylesheet and favicon', () => {
|
||||
const theme = resolveTheme('asf');
|
||||
|
||||
expect(fs.existsSync(theme.css)).toBe(true);
|
||||
expect(theme.css.replaceAll('\\', '/')).toMatch(/themes\/asf\/theme\.css$/);
|
||||
expect(theme.favicon !== null && fs.existsSync(theme.favicon)).toBe(true);
|
||||
});
|
||||
|
||||
it('lists the available themes', () => {
|
||||
expect(availableThemes()).toContain('asf');
|
||||
});
|
||||
|
||||
it.each(['nope', '../asf', 'asf/../asf', '..', 'ASF', 'asf asf'])('rejects %j loudly, naming the real themes', (name) => {
|
||||
expect(() => resolveTheme(name)).toThrow(/Unknown VITE_THEME .*Available themes: .*asf/);
|
||||
});
|
||||
|
||||
it('reports (none) when no theme exists', () => {
|
||||
const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-'));
|
||||
try {
|
||||
expect(() => resolveTheme('x', empty)).toThrow(/\(none\)/);
|
||||
} finally {
|
||||
fs.rmSync(empty, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('asf theme tokens', () => {
|
||||
const tokens = (css: string, block: string) => {
|
||||
const m = css.match(new RegExp(`${block}\\s*\\{([^}]*)\\}`));
|
||||
return new Set([...(m?.[1] ?? '').matchAll(/(--[a-z-]+)\s*:/g)].map((x) => x[1]));
|
||||
};
|
||||
const base = fs.readFileSync(path.resolve(__dirname, '../src/index.css'), 'utf-8');
|
||||
const theme = fs.readFileSync(path.resolve(__dirname, 'asf/theme.css'), 'utf-8');
|
||||
|
||||
it('overrides every existing light and dark design token and invents no structural one', () => {
|
||||
for (const block of ['\\:root', '\\.dark']) {
|
||||
const existing = tokens(base, block);
|
||||
const themed = tokens(theme, block);
|
||||
for (const t of existing) expect(themed, `${block} ${t}`).toContain(t);
|
||||
// Anything beyond the existing tokens must be the theme's own --asf-* palette or the font token.
|
||||
for (const t of themed) {
|
||||
if (!existing.has(t)) expect(t).toMatch(/^--(asf-|font-sans$)/);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('uses the website palette colours exactly', () => {
|
||||
for (const hex of ['#faf7f2', '#f1ebe2', '#e8e0d5', '#232120', '#55504b', '#8a827a', '#e2dad0', '#7f8b76', '#5f6a58', '#475042', '#d9cdbc', '#a4443a']) {
|
||||
expect(theme.toLowerCase()).toContain(hex);
|
||||
}
|
||||
});
|
||||
|
||||
it('self-hosts its fonts (no remote url)', () => {
|
||||
expect(theme).not.toMatch(/https?:\/\//);
|
||||
expect(theme).toContain('@fontsource/jost');
|
||||
expect(theme).toContain('@fontsource/marcellus');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
export interface ResolvedTheme {
|
||||
/** Absolute path of the CSS file to import (the empty module when no theme is selected). */
|
||||
css: string;
|
||||
/** Absolute path of the theme favicon, or null when there is no theme or it ships none. */
|
||||
favicon: string | null;
|
||||
}
|
||||
|
||||
const THEMES_DIR = import.meta.dirname;
|
||||
|
||||
/** Theme folders available next to this file (each holds a theme.css). */
|
||||
export function availableThemes(dir: string = THEMES_DIR): string[] {
|
||||
return fs
|
||||
.readdirSync(dir, { withFileTypes: true })
|
||||
.filter((e) => e.isDirectory() && fs.existsSync(path.join(dir, e.name, 'theme.css')))
|
||||
.map((e) => e.name)
|
||||
.sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves VITE_THEME to files. Unset or blank means "no theme": an empty CSS module, so the admin
|
||||
* looks exactly as it always did. An unknown name is a build error, never a silent fallback, so a
|
||||
* typo in the pipeline cannot ship an unthemed admin unnoticed.
|
||||
*/
|
||||
export function resolveTheme(name: string | undefined, dir: string = THEMES_DIR): ResolvedTheme {
|
||||
const trimmed = (name ?? '').trim();
|
||||
if (trimmed === '') {
|
||||
return { css: path.join(dir, 'none.css'), favicon: null };
|
||||
}
|
||||
|
||||
// The name becomes a path segment: only known theme folders are accepted.
|
||||
const known = availableThemes(dir);
|
||||
if (!known.includes(trimmed)) {
|
||||
throw new Error(
|
||||
`Unknown VITE_THEME "${trimmed}". Available themes: ${known.length > 0 ? known.join(', ') : '(none)'}.`,
|
||||
);
|
||||
}
|
||||
|
||||
const favicon = path.join(dir, trimmed, 'favicon.svg');
|
||||
return {
|
||||
css: path.join(dir, trimmed, 'theme.css'),
|
||||
favicon: fs.existsSync(favicon) ? favicon : null,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user