import type { KnowledgeBasesTemplateDto } from "../dtos/KnowledgeBasesTemplateDto"; import deTranslations from "../../../../public/locales/de/translations.json"; import enTranslations from "../../../../public/locales/en/translations.json"; type SupportedTemplateLanguage = "en" | "de"; type TemplateCatalog = typeof enTranslations; type TemplateKnowledgeBase = Omit & { description: string; links: (Omit & { name: string })[]; title: string; }; type TemplateCategory = Omit & { description: string; sections: (Omit & { description: string; title: string; })[]; title: string; }; type TemplateArticle = Omit< KnowledgeBasesTemplateDto["articles"][number], "contentDraft" | "contentPublished" | "contentPublishedAsText" | "description" | "title" > & { contentDraft: string; contentPublished: string; contentPublishedAsText: string; description: string; title: string; }; type TemplateSource = { knowledgeBases: TemplateKnowledgeBase[]; categories: TemplateCategory[]; articles: TemplateArticle[]; }; const TEMPLATE_CATALOGS: Record = { de: deTranslations, en: enTranslations, }; function templateKey(path: string) { return `knowledgeBase.defaultTemplates.sample.${path}`; } function getCatalogValue(catalog: TemplateCatalog, key: string) { return key.split(".").reduce((current, segment) => { if (!current || typeof current !== "object" || !(segment in current)) { return undefined; } return (current as Record)[segment]; }, catalog); } function translateTemplateValue(language: SupportedTemplateLanguage, key: string) { const value = getCatalogValue(TEMPLATE_CATALOGS[language], key); if (typeof value === "string") { return value; } const fallback = getCatalogValue(TEMPLATE_CATALOGS.en, key); return typeof fallback === "string" ? fallback : key; } const SAMPLE_SOURCE: TemplateSource = { knowledgeBases: [ { basePath: "/", slug: "docs", title: templateKey("knowledgeBases.docs.title"), description: templateKey("knowledgeBases.docs.description"), defaultLanguage: "en", layout: "list", color: 15, enabled: true, languages: ["en"], links: [], logo: "dark", seoImage: "", }, { basePath: "/docs", slug: "center", title: templateKey("knowledgeBases.center.title"), description: templateKey("knowledgeBases.center.description"), defaultLanguage: "en", layout: "articles", color: 16, enabled: true, languages: ["de", "en"], links: [ { name: templateKey("knowledgeBases.center.links.backToSite"), href: "/", order: 1, }, ], logo: "dark", seoImage: "", }, ], categories: [ { knowledgeBaseSlug: "docs", slug: "introduction", order: 1, title: templateKey("categories.introduction.title"), description: templateKey("categories.introduction.description"), icon: "", language: "en", seoImage: "", sections: [], }, { knowledgeBaseSlug: "center", slug: "getting-started", order: 1, title: templateKey("categories.gettingStarted.title"), description: templateKey("categories.gettingStarted.description"), icon: ' ', language: "en", seoImage: "", sections: [], }, { knowledgeBaseSlug: "center", slug: "kategorie-1", order: 1, title: templateKey("categories.gettingStartedDe.title"), description: templateKey("categories.gettingStartedDe.description"), icon: ' ', language: "de", seoImage: "", sections: [ { order: 1, title: templateKey("categories.gettingStartedDe.sections.basics.title"), description: templateKey("categories.gettingStartedDe.sections.basics.description"), }, ], }, { knowledgeBaseSlug: "center", slug: "kategorie-2", order: 2, title: templateKey("categories.accountManagementDe.title"), description: templateKey("categories.accountManagementDe.description"), icon: ' ', language: "de", seoImage: "", sections: [], }, { knowledgeBaseSlug: "center", slug: "account-management", order: 2, title: templateKey("categories.accountManagement.title"), description: templateKey("categories.accountManagement.description"), icon: ' ', language: "en", seoImage: "", sections: [], }, ], articles: [ { knowledgeBaseSlug: "docs", categorySlug: "introduction", categorySectionOrder: null, slug: "example-site-knowledge-base", title: templateKey("articles.exampleSiteKnowledgeBase.title"), description: templateKey("articles.exampleSiteKnowledgeBase.description"), order: 0, contentDraft: templateKey("articles.exampleSiteKnowledgeBase.content.markup"), contentPublished: templateKey("articles.exampleSiteKnowledgeBase.content.markup"), contentPublishedAsText: templateKey("articles.exampleSiteKnowledgeBase.content.text"), contentType: "wysiwyg", language: "en", featuredOrder: 2, seoImage: "", publishedAt: "2023-07-01T23:42:31.371Z", createdByUserEmail: null, relatedArticles: [], }, { knowledgeBaseSlug: "docs", categorySlug: "introduction", categorySectionOrder: null, slug: "publish-product-documentation", title: templateKey("articles.publishProductDocumentation.title"), description: templateKey("articles.publishProductDocumentation.description"), order: 0, contentDraft: templateKey("articles.publishProductDocumentation.content.markup"), contentPublished: templateKey("articles.publishProductDocumentation.content.markup"), contentPublishedAsText: templateKey("articles.publishProductDocumentation.content.text"), contentType: "wysiwyg", language: "en", featuredOrder: 1, seoImage: "", publishedAt: "2023-07-01T21:49:40.834Z", createdByUserEmail: null, relatedArticles: [], }, { knowledgeBaseSlug: "center", categorySlug: "kategorie-1", categorySectionOrder: 1, slug: "beispiel-2", title: templateKey("articles.structureKnowledgeBaseDe.title"), description: templateKey("articles.structureKnowledgeBaseDe.description"), order: 0, contentDraft: templateKey("articles.structureKnowledgeBaseDe.content.markup"), contentPublished: templateKey("articles.structureKnowledgeBaseDe.content.markup"), contentPublishedAsText: templateKey("articles.structureKnowledgeBaseDe.content.text"), contentType: "wysiwyg", language: "de", featuredOrder: 3, seoImage: "", publishedAt: "2023-07-01T21:39:51.857Z", createdByUserEmail: null, relatedArticles: [], }, { knowledgeBaseSlug: "center", categorySlug: "getting-started", categorySectionOrder: null, slug: "structure-your-help-center", title: templateKey("articles.structureYourHelpCenter.title"), description: templateKey("articles.structureYourHelpCenter.description"), order: 0, contentDraft: templateKey("articles.structureYourHelpCenter.content.markup"), contentPublished: templateKey("articles.structureYourHelpCenter.content.markup"), contentPublishedAsText: templateKey("articles.structureYourHelpCenter.content.text"), contentType: "wysiwyg", language: "en", featuredOrder: 2, seoImage: "", publishedAt: "2023-07-01T23:35:32.524Z", createdByUserEmail: null, relatedArticles: [ { slug: "welcome-to-the-help-center", }, { slug: "manage-team-access", }, ], }, { knowledgeBaseSlug: "center", categorySlug: "getting-started", categorySectionOrder: null, slug: "welcome-to-the-help-center", title: templateKey("articles.welcomeToTheHelpCenter.title"), description: templateKey("articles.welcomeToTheHelpCenter.description"), order: 0, contentDraft: templateKey("articles.welcomeToTheHelpCenter.content.markup"), contentPublished: templateKey("articles.welcomeToTheHelpCenter.content.markup"), contentPublishedAsText: templateKey("articles.welcomeToTheHelpCenter.content.text"), contentType: "wysiwyg", language: "en", featuredOrder: 1, seoImage: "", publishedAt: "2023-07-01T21:39:38.696Z", createdByUserEmail: null, relatedArticles: [], }, { knowledgeBaseSlug: "center", categorySlug: "kategorie-1", categorySectionOrder: null, slug: "beispiel-1", title: templateKey("articles.welcomeToKnowledgeBaseDe.title"), description: templateKey("articles.welcomeToKnowledgeBaseDe.description"), order: 0, contentDraft: templateKey("articles.welcomeToKnowledgeBaseDe.content.markup"), contentPublished: templateKey("articles.welcomeToKnowledgeBaseDe.content.markup"), contentPublishedAsText: templateKey("articles.welcomeToKnowledgeBaseDe.content.text"), contentType: "wysiwyg", language: "de", featuredOrder: 3, seoImage: "", publishedAt: "2023-07-01T21:39:49.570Z", createdByUserEmail: null, relatedArticles: [], }, { knowledgeBaseSlug: "center", categorySlug: "kategorie-2", categorySectionOrder: null, slug: "beispiel-3", title: templateKey("articles.manageTeamAccessDe.title"), description: templateKey("articles.manageTeamAccessDe.description"), order: 0, contentDraft: templateKey("articles.manageTeamAccessDe.content.markup"), contentPublished: templateKey("articles.manageTeamAccessDe.content.markup"), contentPublishedAsText: templateKey("articles.manageTeamAccessDe.content.text"), contentType: "wysiwyg", language: "de", featuredOrder: null, seoImage: "", publishedAt: "2023-07-01T21:39:47.550Z", createdByUserEmail: null, relatedArticles: [], }, { knowledgeBaseSlug: "center", categorySlug: "account-management", categorySectionOrder: null, slug: "manage-team-access", title: templateKey("articles.manageTeamAccess.title"), description: templateKey("articles.manageTeamAccess.description"), order: 0, contentDraft: templateKey("articles.manageTeamAccess.content.markup"), contentPublished: templateKey("articles.manageTeamAccess.content.markup"), contentPublishedAsText: templateKey("articles.manageTeamAccess.content.text"), contentType: "wysiwyg", language: "en", featuredOrder: null, seoImage: "", publishedAt: "2023-07-01T21:39:36.515Z", createdByUserEmail: null, relatedArticles: [], }, ], }; function buildSample(language: SupportedTemplateLanguage): KnowledgeBasesTemplateDto { const knowledgeBases = SAMPLE_SOURCE.knowledgeBases .filter((kb) => kb.languages.includes(language)) .map((kb) => ({ ...kb, title: translateTemplateValue(language, kb.title), description: translateTemplateValue(language, kb.description), defaultLanguage: language, languages: [language], links: kb.links.map((link) => ({ ...link, name: translateTemplateValue(language, link.name), })), })); const knowledgeBaseSlugs = new Set(knowledgeBases.map((kb) => kb.slug)); const categories = SAMPLE_SOURCE.categories .filter((category) => category.language === language && knowledgeBaseSlugs.has(category.knowledgeBaseSlug)) .map((category) => ({ ...category, title: translateTemplateValue(language, category.title), description: translateTemplateValue(language, category.description), sections: category.sections.map((section) => ({ ...section, title: translateTemplateValue(language, section.title), description: translateTemplateValue(language, section.description), })), })); const categorySlugs = new Set(categories.map((category) => `${category.knowledgeBaseSlug}:${category.slug}`)); const articles = SAMPLE_SOURCE.articles .filter( (article) => article.language === language && knowledgeBaseSlugs.has(article.knowledgeBaseSlug) && (!article.categorySlug || categorySlugs.has(`${article.knowledgeBaseSlug}:${article.categorySlug}`)) ) .map((article) => ({ ...article, title: translateTemplateValue(language, article.title), description: translateTemplateValue(language, article.description), contentDraft: translateTemplateValue(language, article.contentDraft), contentPublished: translateTemplateValue(language, article.contentPublished), contentPublishedAsText: translateTemplateValue(language, article.contentPublishedAsText), })); return { knowledgeBases, categories, articles, }; } const SAMPLE_EN = buildSample("en"); const SAMPLE_DE = buildSample("de"); const SAMPLE = SAMPLE_EN; export default { SAMPLE, SAMPLE_DE, SAMPLE_EN, };