From fcf5490d5a4e82d89a2940d9e0472ccb23b8d58e Mon Sep 17 00:00:00 2001 From: Mario Linz Date: Mon, 30 May 2022 16:52:12 +0200 Subject: [PATCH] =?UTF-8?q?Content=20Collection=20um=20Tags=20ChipArray=20?= =?UTF-8?q?erweitert,=20um=20eine=20M=C3=B6glichkeit=20zu=20schaffen,=20St?= =?UTF-8?q?ichworte=20zum=20Verkn=C3=BCpfen=20der=20Seiten=20zwischen=20de?= =?UTF-8?q?n=20Sprachen=20zu=20schaffen...(WIP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/collections/content.yml | 18 ++++++++++++++++++ src/api.ts | 4 ++-- src/components/routes/Content.svelte | 11 +++++++++-- src/components/widgets/LanguageChooser.svelte | 16 +++++++++------- types/global.d.ts | 3 ++- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/api/collections/content.yml b/api/collections/content.yml index 435fd0b..fc83484 100644 --- a/api/collections/content.yml +++ b/api/collections/content.yml @@ -107,6 +107,24 @@ hooks: # Feldliste der Kollektion fields: - !include fields/_locale.yml + - name: tags + type: string[] + meta: + helperText: + de: "Entsprechende Seiten in einer anderen Sprache, die mit den selben zugewiesenen Stichworten gekennzeichnet sind, können bei Umschaltung der Seitensprache gefunden werden." + en: "" + widget: chipArray + label: + de: Verknüpfungs-Stichworte + en: Linking Tags + defaultValue: [] + choices: + endpoint: "tags" + mapping: + id: "id" + name: "name" + params: + sort: "name" - name: path type: string index: [single, unique] diff --git a/src/api.ts b/src/api.ts index 4edd20c..2627e7d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -186,10 +186,10 @@ export const sendEmail = async (type: string = "contactForm", data: any, noToken }) } -export const getContent = async (path: string, lang: string): Promise => { +export const getContent = async (path: string, lang: string, filter?: APIParams): Promise => { const c = await api("content", { limit: 1, - filter: { path, locale: lang }, + filter: { path, locale: lang, ...filter }, }) if (c?.data?.length) { return c.data[0] diff --git a/src/components/routes/Content.svelte b/src/components/routes/Content.svelte index 65d4c36..40e40f5 100644 --- a/src/components/routes/Content.svelte +++ b/src/components/routes/Content.svelte @@ -11,8 +11,15 @@ let currentDomain = window.location.protocol + "//" + window.location.host const load = () => { + let filter = {} + if (content?.tags) { + filter = { + tags: { $in: content?.tags }, + } + } + loading = true - getContent(path, $currentLang) + getContent(path, $currentLang, filter) .then((c) => { content = c }) @@ -31,7 +38,7 @@ {content?.name ? content?.name + " - " : ""}{$generalInfo?.meta?.metaTitle} -{path} +
diff --git a/src/components/widgets/LanguageChooser.svelte b/src/components/widgets/LanguageChooser.svelte index b8997c6..ae6a465 100644 --- a/src/components/widgets/LanguageChooser.svelte +++ b/src/components/widgets/LanguageChooser.svelte @@ -4,13 +4,15 @@ $: languages = [] - $: if ($navigations?.length) { - $navigations.forEach((nav) => { - if (!languages.includes(nav.locale)) { - languages.push(nav.locale) - } - }) - languages = languages + $: { + if ($navigations?.length) { + $navigations.forEach((nav) => { + if (!languages.includes(nav.locale)) { + languages.push(nav.locale) + } + }) + languages = languages + } } const setLanguage = (lang: string) => { diff --git a/types/global.d.ts b/types/global.d.ts index 727d208..777f6c9 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -19,7 +19,8 @@ interface ContentBlock { interface Content { id: string - name: string + locale: string + tags?: string[] path: string blocks: ContentBlock[] }