refactor: apply Clean Architecture principles

- Extract EXIF and Swipe logic into custom hooks for Lightbox
- Extract Map layout data formatting into mapService
- Extract AlbumDetailView and SubpageGridView components from page router
- Restructure monolithic config.ts into clean config/ directory
This commit is contained in:
ralksta
2026-03-08 18:55:45 +01:00
parent 89dfef6144
commit 23d8bf0425
14 changed files with 721 additions and 204 deletions

30
lib/config/parser.ts Normal file
View File

@@ -0,0 +1,30 @@
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
export function loadYaml<T>(filename: string): T {
const yamlPath = path.join(process.cwd(), 'content', filename);
if (!fs.existsSync(yamlPath)) {
if (filename === 'gallery.yaml') {
throw new Error(
`Required config not found: ${yamlPath}\n` +
`Copy content/gallery.yaml.example to content/gallery.yaml and add your album IDs.`,
);
}
return {} as T;
}
const raw = fs.readFileSync(yamlPath, 'utf8');
return (yaml.load(raw) || {}) as T;
}
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
export function validateUuid(id: string, context: string): string {
const trimmed = id.trim();
if (!UUID_REGEX.test(trimmed)) {
throw new Error(`Invalid UUID in ${context}: "${trimmed}"`);
}
return trimmed;
}