feat: implement device-specific configurations for desktop, tablet, and mobile
All checks were successful
Production Build & Deploy / build-and-deploy (push) Successful in 57s
All checks were successful
Production Build & Deploy / build-and-deploy (push) Successful in 57s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { detectDeviceType } from './deviceDetect';
|
||||
export interface UIComponent {
|
||||
id: string; // Eindeutige ID (z.B. uuid / timestamp)
|
||||
slotId: string; // Platz-ID (z.B. 'hero-badge-slot', 'hero-actions-slot', 'bento-slot-1')
|
||||
@@ -206,11 +206,20 @@ function readJsonFile<T>(filePath: string, fallback: T): T {
|
||||
}
|
||||
}
|
||||
|
||||
export function loadWaasConfigs() {
|
||||
export function loadWaasConfigs(userAgent: string = '') {
|
||||
const dataDir = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||
const sitePath = path.join(dataDir, 'site.config.json');
|
||||
const themePath = path.join(dataDir, 'theme.config.json');
|
||||
const smtpPath = path.join(dataDir, 'smtp.config.json');
|
||||
const device = detectDeviceType(userAgent);
|
||||
const deviceSitePath = path.join(dataDir, `site.${device}.config.json`);
|
||||
const genericSitePath = path.join(dataDir, 'site.config.json');
|
||||
const sitePath = fs.existsSync(deviceSitePath) ? deviceSitePath : genericSitePath;
|
||||
|
||||
const deviceThemePath = path.join(dataDir, `theme.${device}.config.json`);
|
||||
const genericThemePath = path.join(dataDir, 'theme.config.json');
|
||||
const themePath = fs.existsSync(deviceThemePath) ? deviceThemePath : genericThemePath;
|
||||
|
||||
const deviceSmtpPath = path.join(dataDir, `smtp.${device}.config.json`);
|
||||
const genericSmtpPath = path.join(dataDir, 'smtp.config.json');
|
||||
const smtpPath = fs.existsSync(deviceSmtpPath) ? deviceSmtpPath : genericSmtpPath;
|
||||
|
||||
const rawSite = readJsonFile<Partial<SiteConfig>>(sitePath, FALLBACK_SITE_CONFIG);
|
||||
const siteConfig: SiteConfig = {
|
||||
|
||||
14
src/utils/deviceDetect.ts
Normal file
14
src/utils/deviceDetect.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export type DeviceType = 'desktop' | 'tablet' | 'mobile';
|
||||
|
||||
/**
|
||||
* Simple User-Agent based device detection.
|
||||
* Returns 'desktop' by default when detection fails.
|
||||
*/
|
||||
export function detectDeviceType(userAgent: string): DeviceType {
|
||||
const ua = userAgent.toLowerCase();
|
||||
// Tablet detection (including iPad which reports as Mac on iOS 13+)
|
||||
if (/tablet|ipad/.test(ua)) return 'tablet';
|
||||
// Mobile detection (phones and Android)
|
||||
if (/mobile|iphone|android/.test(ua)) return 'mobile';
|
||||
return 'desktop';
|
||||
}
|
||||
Reference in New Issue
Block a user