387 lines
17 KiB
TypeScript
387 lines
17 KiB
TypeScript
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<KnowledgeBasesTemplateDto["knowledgeBases"][number], "description" | "links" | "title"> & {
|
|
description: string;
|
|
links: (Omit<KnowledgeBasesTemplateDto["knowledgeBases"][number]["links"][number], "name"> & { name: string })[];
|
|
title: string;
|
|
};
|
|
type TemplateCategory = Omit<KnowledgeBasesTemplateDto["categories"][number], "description" | "sections" | "title"> & {
|
|
description: string;
|
|
sections: (Omit<KnowledgeBasesTemplateDto["categories"][number]["sections"][number], "description" | "title"> & {
|
|
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<SupportedTemplateLanguage, TemplateCatalog> = {
|
|
de: deTranslations,
|
|
en: enTranslations,
|
|
};
|
|
|
|
function templateKey(path: string) {
|
|
return `knowledgeBase.defaultTemplates.sample.${path}`;
|
|
}
|
|
|
|
function getCatalogValue(catalog: TemplateCatalog, key: string) {
|
|
return key.split(".").reduce<unknown>((current, segment) => {
|
|
if (!current || typeof current !== "object" || !(segment in current)) {
|
|
return undefined;
|
|
}
|
|
return (current as Record<string, unknown>)[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: '<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="50" height="50" viewBox="0 0 50 50" className={className} fill="currentColor"> <path d="M47.16,21.221l-5.91-0.966c-0.346-1.186-0.819-2.326-1.411-3.405l3.45-4.917c0.279-0.397,0.231-0.938-0.112-1.282 l-3.889-3.887c-0.347-0.346-0.893-0.391-1.291-0.104l-4.843,3.481c-1.089-0.602-2.239-1.08-3.432-1.427l-1.031-5.886 C28.607,2.35,28.192,2,27.706,2h-5.5c-0.49,0-0.908,0.355-0.987,0.839l-0.956,5.854c-1.2,0.345-2.352,0.818-3.437,1.412l-4.83-3.45 c-0.399-0.285-0.942-0.239-1.289,0.106L6.82,10.648c-0.343,0.343-0.391,0.883-0.112,1.28l3.399,4.863 c-0.605,1.095-1.087,2.254-1.438,3.46l-5.831,0.971c-0.482,0.08-0.836,0.498-0.836,0.986v5.5c0,0.485,0.348,0.9,0.825,0.985 l5.831,1.034c0.349,1.203,0.831,2.362,1.438,3.46l-3.441,4.813c-0.284,0.397-0.239,0.942,0.106,1.289l3.888,3.891 c0.343,0.343,0.884,0.391,1.281,0.112l4.87-3.411c1.093,0.601,2.248,1.078,3.445,1.424l0.976,5.861C21.3,47.647,21.717,48,22.206,48 h5.5c0.485,0,0.9-0.348,0.984-0.825l1.045-5.89c1.199-0.353,2.348-0.833,3.43-1.435l4.905,3.441 c0.398,0.281,0.938,0.232,1.282-0.111l3.888-3.891c0.346-0.347,0.391-0.894,0.104-1.292l-3.498-4.857 c0.593-1.08,1.064-2.222,1.407-3.408l5.918-1.039c0.479-0.084,0.827-0.5,0.827-0.985v-5.5C47.999,21.718,47.644,21.3,47.16,21.221z M25,32c-3.866,0-7-3.134-7-7c0-3.866,3.134-7,7-7s7,3.134,7,7C32,28.866,28.866,32,25,32z"></path> </svg>',
|
|
language: "en",
|
|
seoImage: "",
|
|
sections: [],
|
|
},
|
|
{
|
|
knowledgeBaseSlug: "center",
|
|
slug: "kategorie-1",
|
|
order: 1,
|
|
title: templateKey("categories.gettingStartedDe.title"),
|
|
description: templateKey("categories.gettingStartedDe.description"),
|
|
icon: '<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="50" height="50" viewBox="0 0 50 50" className={className} fill="currentColor"> <path d="M47.16,21.221l-5.91-0.966c-0.346-1.186-0.819-2.326-1.411-3.405l3.45-4.917c0.279-0.397,0.231-0.938-0.112-1.282 l-3.889-3.887c-0.347-0.346-0.893-0.391-1.291-0.104l-4.843,3.481c-1.089-0.602-2.239-1.08-3.432-1.427l-1.031-5.886 C28.607,2.35,28.192,2,27.706,2h-5.5c-0.49,0-0.908,0.355-0.987,0.839l-0.956,5.854c-1.2,0.345-2.352,0.818-3.437,1.412l-4.83-3.45 c-0.399-0.285-0.942-0.239-1.289,0.106L6.82,10.648c-0.343,0.343-0.391,0.883-0.112,1.28l3.399,4.863 c-0.605,1.095-1.087,2.254-1.438,3.46l-5.831,0.971c-0.482,0.08-0.836,0.498-0.836,0.986v5.5c0,0.485,0.348,0.9,0.825,0.985 l5.831,1.034c0.349,1.203,0.831,2.362,1.438,3.46l-3.441,4.813c-0.284,0.397-0.239,0.942,0.106,1.289l3.888,3.891 c0.343,0.343,0.884,0.391,1.281,0.112l4.87-3.411c1.093,0.601,2.248,1.078,3.445,1.424l0.976,5.861C21.3,47.647,21.717,48,22.206,48 h5.5c0.485,0,0.9-0.348,0.984-0.825l1.045-5.89c1.199-0.353,2.348-0.833,3.43-1.435l4.905,3.441 c0.398,0.281,0.938,0.232,1.282-0.111l3.888-3.891c0.346-0.347,0.391-0.894,0.104-1.292l-3.498-4.857 c0.593-1.08,1.064-2.222,1.407-3.408l5.918-1.039c0.479-0.084,0.827-0.5,0.827-0.985v-5.5C47.999,21.718,47.644,21.3,47.16,21.221z M25,32c-3.866,0-7-3.134-7-7c0-3.866,3.134-7,7-7s7,3.134,7,7C32,28.866,28.866,32,25,32z"></path> </svg>',
|
|
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: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"> <path fillRule="evenodd" d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z" clipRule="evenodd" /> </svg>',
|
|
language: "de",
|
|
seoImage: "",
|
|
sections: [],
|
|
},
|
|
{
|
|
knowledgeBaseSlug: "center",
|
|
slug: "account-management",
|
|
order: 2,
|
|
title: templateKey("categories.accountManagement.title"),
|
|
description: templateKey("categories.accountManagement.description"),
|
|
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"> <path fillRule="evenodd" d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10A1 1 0 018 18v-5H4a1 1 0 01-.82-1.573l7-10a1 1 0 011.12-.38z" clipRule="evenodd" /> </svg>',
|
|
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,
|
|
};
|