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[] }