Files
websitedev/proto/src/content/index.ts
T
Do Siki 0047e1b441
CI — Test & Build / 🧪 Run Tests & Generate Reports (push) Waiting to run
CI — Test & Build / 🏗️ Build Docker Image (push) Blocked by required conditions
CI — Test & Build / 🐳 Docker integration & API E2E (push) Blocked by required conditions
CI — Test & Build / 🌐 Staging Playwright smoke (push) Waiting to run
feat: harden content workflows and staging smoke tests
2026-08-17 16:08:57 +02:00

79 lines
2.5 KiB
TypeScript
Executable File

/**
* Content Loader - Centralized content management
*
* This module provides type-safe access to all JSON content files.
* Content can be easily modified by editing the JSON files without code changes.
*
* Usage:
* import { content, getPageContent } from '@/content'
*
* // Access specific page content
* const aboutContent = content.pages.about
*
* // Or use the helper function
* const servicesContent = getPageContent('services')
*/
import type {
SiteContent,
CommonContent,
HomePageContent,
AboutPageContent,
ServicesPageContent,
ContactPageContent,
LegalPageContent
} from './types'
import { validateContent } from './schema'
// Import JSON files
import commonJson from './common.json'
import homeJson from './pages/home.json'
import aboutJson from './pages/about.json'
import servicesJson from './pages/services.json'
import contactJson from './pages/contact.json'
import adatvedelemJson from './pages/adatvedelem.json'
import hasznalatiFeltetelekJson from './pages/hasznalati-feltetelek.json'
function loadValidatedContent<T>(fileKey: string, value: unknown): T {
const result = validateContent(fileKey, value)
if (!result.ok) {
throw new Error(`Érvénytelen content JSON (${fileKey}): ${result.errors.join('; ')}`)
}
return value as T
}
// Runtime validation prevents malformed JSON from silently reaching the UI.
const common = loadValidatedContent<CommonContent>('common', commonJson)
const home = loadValidatedContent<HomePageContent>('home', homeJson)
const about = loadValidatedContent<AboutPageContent>('about', aboutJson)
const services = loadValidatedContent<ServicesPageContent>('services', servicesJson)
const contact = loadValidatedContent<ContactPageContent>('contact', contactJson)
const adatvedelem = loadValidatedContent<LegalPageContent>('adatvedelem', adatvedelemJson)
const hasznalatiFeltetelek = loadValidatedContent<LegalPageContent>('hasznalatiFeltetelek', hasznalatiFeltetelekJson)
// Combined content object
export const content: SiteContent = {
common,
pages: {
home,
about,
services,
contact,
adatvedelem,
hasznalatiFeltetelek
}
}
// Helper function to get page content with type safety
export function getPageContent<T extends keyof SiteContent['pages']>(
page: T
): SiteContent['pages'][T] {
return content.pages[page]
}
// Export individual content for direct imports
export { common, home, about, services, contact, adatvedelem, hasznalatiFeltetelek }
// Re-export types
export * from './types'