project setup with core files including configuration, package management, and basic structure. Added .gitignore, README, and various TypeScript types for CMS components. Implemented initial components and layouts for the application.
This commit is contained in:
93
middlelayer/adapters/Mock/mockdata.ts
Normal file
93
middlelayer/adapters/Mock/mockdata.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import type { DataAdapter } from "../interface";
|
||||
import type { PageSeo, Page, Navigation, Product } from "../../types/index";
|
||||
import { generateMockPageConfig } from "./_cms/mockPageConfig";
|
||||
import { generateMockPages } from "./_cms/mockPage";
|
||||
import { generateMockNavigation } from "./_cms/mockNavigation";
|
||||
import { generateRandomProducts } from "./_cms/mockProducts";
|
||||
import { PageMapper } from "../../mappers/pageMapper";
|
||||
import { getTranslations } from "./_i18n/mockTranslations";
|
||||
import type { TranslationsData } from "./_i18n/mockTranslations";
|
||||
|
||||
/**
|
||||
* Mockdata Adapter - verwendet lokale Mock-Daten
|
||||
*/
|
||||
export class MockdataAdapter implements DataAdapter {
|
||||
async getProducts(limit: number = 4): Promise<Product[]> {
|
||||
return generateRandomProducts(limit);
|
||||
}
|
||||
|
||||
async getProduct(id: string): Promise<Product | null> {
|
||||
const products = generateRandomProducts(1);
|
||||
return products[0] ? { ...products[0], id } : null;
|
||||
}
|
||||
async getPage(slug: string, locale?: string): Promise<Page | null> {
|
||||
// Verwende Locale für locale-spezifische Inhalte
|
||||
const pages = generateMockPages(locale || "de");
|
||||
const page = pages[slug];
|
||||
if (!page) return null;
|
||||
|
||||
return PageMapper.fromCms(page);
|
||||
}
|
||||
|
||||
async getPages(locale?: string): Promise<Page[]> {
|
||||
// Verwende Locale für locale-spezifische Inhalte
|
||||
const pages = generateMockPages(locale || "de");
|
||||
return PageMapper.fromCmsArray(Object.values(pages));
|
||||
}
|
||||
|
||||
async getPageSeo(locale?: string): Promise<PageSeo> {
|
||||
// Verwende Locale für locale-spezifische SEO-Daten
|
||||
const pageConfig = generateMockPageConfig(locale || "de");
|
||||
return {
|
||||
title: pageConfig.seoTitle,
|
||||
description: pageConfig.seoDescription,
|
||||
metaRobotsIndex: "index",
|
||||
metaRobotsFollow: "follow",
|
||||
};
|
||||
}
|
||||
|
||||
async getNavigation(locale?: string): Promise<Navigation> {
|
||||
// Verwende Locale für locale-spezifische Navigation
|
||||
const nav = generateMockNavigation(locale || "de");
|
||||
const pages = generateMockPages(locale || "de");
|
||||
|
||||
// Konvertiere die Links zu NavigationLink-Format
|
||||
const links = nav.links.map((link: any) => {
|
||||
// Wenn es eine Page ist (hat slug)
|
||||
if (link.fields.slug) {
|
||||
const page = pages[link.fields.slug];
|
||||
if (page) {
|
||||
return {
|
||||
slug: page.slug,
|
||||
name: page.name,
|
||||
linkName: page.linkName,
|
||||
url: page.slug,
|
||||
icon: page.icon,
|
||||
newTab: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
// Wenn es ein Link ist
|
||||
return {
|
||||
name: link.fields.name || link.fields.linkName,
|
||||
linkName: link.fields.linkName,
|
||||
url: link.fields.url,
|
||||
icon: link.fields.icon,
|
||||
newTab: link.fields.newTab || false,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
name: nav.name,
|
||||
internal: nav.internal,
|
||||
links: links.filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
||||
async getTranslations(
|
||||
locale: string = "de",
|
||||
namespace?: string
|
||||
): Promise<TranslationsData> {
|
||||
return getTranslations(locale, namespace);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user