From fc7fb0967cdcf5e59a0874e89a02804921c1d8eb Mon Sep 17 00:00:00 2001 From: Manuel Brandstetter Date: Tue, 21 Nov 2023 19:18:03 +0100 Subject: [PATCH] Changes --- astro.config.mjs | 8 ++--- src/pages/{ => [lang]}/Legal/Cookies.astro | 0 src/pages/{ => [lang]}/Legal/Legal.scss | 0 src/pages/{ => [lang]}/Legal/Privacy.astro | 0 src/pages/{ => [lang]}/Legal/Terms.astro | 0 src/pages/[lang]/index.astro | 29 +++++++++++++++++++ src/pages/index.astro | 20 ------------- src/utils/client.js | 10 ------- src/utils/directus.ts | 26 +++++++++++++++++ .../ReachNewHeights/ReachNewHeights.astro | 27 ++++++++--------- 10 files changed, 71 insertions(+), 49 deletions(-) rename src/pages/{ => [lang]}/Legal/Cookies.astro (100%) rename src/pages/{ => [lang]}/Legal/Legal.scss (100%) rename src/pages/{ => [lang]}/Legal/Privacy.astro (100%) rename src/pages/{ => [lang]}/Legal/Terms.astro (100%) create mode 100644 src/pages/[lang]/index.astro delete mode 100644 src/pages/index.astro delete mode 100644 src/utils/client.js create mode 100644 src/utils/directus.ts diff --git a/astro.config.mjs b/astro.config.mjs index 8bac5d1..998c209 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -4,8 +4,8 @@ import react from "@astrojs/react"; // https://astro.build/config export default defineConfig({ - integrations: [react()], - redirects: { - "/legal": "/legal/privacy", - }, + integrations: [react()], + redirects: { + "/legal": "/legal/privacy", + }, }); diff --git a/src/pages/Legal/Cookies.astro b/src/pages/[lang]/Legal/Cookies.astro similarity index 100% rename from src/pages/Legal/Cookies.astro rename to src/pages/[lang]/Legal/Cookies.astro diff --git a/src/pages/Legal/Legal.scss b/src/pages/[lang]/Legal/Legal.scss similarity index 100% rename from src/pages/Legal/Legal.scss rename to src/pages/[lang]/Legal/Legal.scss diff --git a/src/pages/Legal/Privacy.astro b/src/pages/[lang]/Legal/Privacy.astro similarity index 100% rename from src/pages/Legal/Privacy.astro rename to src/pages/[lang]/Legal/Privacy.astro diff --git a/src/pages/Legal/Terms.astro b/src/pages/[lang]/Legal/Terms.astro similarity index 100% rename from src/pages/Legal/Terms.astro rename to src/pages/[lang]/Legal/Terms.astro diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro new file mode 100644 index 0000000..204ccc6 --- /dev/null +++ b/src/pages/[lang]/index.astro @@ -0,0 +1,29 @@ +--- +import type { GetStaticPaths } from "astro"; +import ReachNewHeights from "../../views/ReachNewHeights/ReachNewHeights.astro"; +import Choices from "../../components/Choices"; +import { Uniqueness } from "../../components/Uniqueness"; +import { Mobile } from "../../components/Mobile"; +import Layout from "../../layouts/Layout.astro"; +import TargetUser from "../../views/TargetUser/TargetUser.astro"; +import Features from "../../views/Features/Features.astro"; +import { AboutUs } from "../../views/AboutUs/AboutUs"; + +export const getStaticPaths = (() => { + return [ + {params: {lang: "en"}}, + {params: {lang: "de"}}, + ]; +}) satisfies GetStaticPaths; + +--- + + + + + + + + + + diff --git a/src/pages/index.astro b/src/pages/index.astro deleted file mode 100644 index c291b38..0000000 --- a/src/pages/index.astro +++ /dev/null @@ -1,20 +0,0 @@ ---- -import ReachNewHeights from "../views/ReachNewHeights/ReachNewHeights.astro"; -import Choices from "../components/Choices"; -import { Uniqueness } from "../components/Uniqueness"; -import { Mobile } from "../components/Mobile"; -import Layout from "../layouts/Layout.astro"; -import TargetUser from "../views/TargetUser/TargetUser.astro"; -import Features from "../views/Features/Features.astro"; -import { AboutUs } from "../views/AboutUs/AboutUs"; ---- - - - - - - - - - - diff --git a/src/utils/client.js b/src/utils/client.js deleted file mode 100644 index 0fe1aef..0000000 --- a/src/utils/client.js +++ /dev/null @@ -1,10 +0,0 @@ -import {createDirectus, rest, staticToken} from '@directus/sdk'; - -const directusUrl = import.meta.env.DIRECTUS_URL; -const directusToken = import.meta.env.DIRECTUS_TOKEN; - -const directusClient = createDirectus(directusUrl) - .with(staticToken(directusToken)) - .with(rest()); - -export default directusClient; diff --git a/src/utils/directus.ts b/src/utils/directus.ts new file mode 100644 index 0000000..66a7271 --- /dev/null +++ b/src/utils/directus.ts @@ -0,0 +1,26 @@ +import {createDirectus, readItems, rest, staticToken} from '@directus/sdk'; + +const directusUrl = import.meta.env.DIRECTUS_URL; +const directusToken = import.meta.env.DIRECTUS_TOKEN; + +const directusClient = createDirectus(directusUrl) + .with(staticToken(directusToken)) + .with(rest()); + +export default async function getTranslatedContent(collection: string, language: string) { + const content = await directusClient.request<{id: string, translations: [Record]}>(readItems(collection, { + deep: { + translations: { + _filter: { + languages_code: { + _eq: language + }, + }, + }, + }, + fields: ['*', 'translations.*'], + limit: 1 + })); + + return content.translations[0]; +} diff --git a/src/views/ReachNewHeights/ReachNewHeights.astro b/src/views/ReachNewHeights/ReachNewHeights.astro index 4d4f0b8..4b0738b 100644 --- a/src/views/ReachNewHeights/ReachNewHeights.astro +++ b/src/views/ReachNewHeights/ReachNewHeights.astro @@ -1,27 +1,24 @@ --- -import { readItems } from "@directus/sdk"; import { Link } from "../../components/Link/Link"; //import Icon from "../../components/Icon"; import "./ReachNewHeights.scss"; -import directusClient from "../../utils/client"; - -const content = await directusClient.request(readItems("Hero_Section", { - fields: ["*.*"] -})); +import getTranslatedContent from "../../utils/directus"; +const {lang} = Astro.params; +const content = await getTranslatedContent("Hero_Section", lang!); --- +
- {JSON.stringify(content)}
-

{}

-

{}

+

{content.header}

+

{content.paragraph}

- {} - {} + {content.cta} + {content.detailsButton}
What is it about? -

{}

-

{}

+

{content.detailsHeader1}

+

{content.detailsText1}

@@ -61,8 +58,8 @@ const content = await directusClient.request(readItems("Hero_Section", { alt="How can it be used?" class="information-item__icon information-item__icon--dark" /> -

{}

-

{}

+

{content.detailsHeader2}

+

{content.detailsText2}