From 716b5535ae06a9ac1bb232cbd1530d070984f10a Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Sat, 10 May 2025 17:37:58 +0200 Subject: [PATCH 1/2] change: loading performance --- app.vue | 14 ++--- components/Footer.vue | 5 +- components/Header.vue | 8 ++- components/base/ListImageItem.vue | 10 ++-- components/shared/EmphasiseArticle.vue | 2 +- components/shared/List.vue | 6 +-- composables/calculateTitle.ts | 11 ---- composables/provideGlobal.ts | 9 ---- composables/useGlobal.ts | 26 ++++++++++ .../{calculateSitemap.ts => useSitemap.ts} | 52 ++++++++----------- layouts/landing.vue | 3 +- pages/[...slug].vue | 41 ++++++++------- plugins/global.ts | 15 ++++++ plugins/sitemap.ts | 25 +++++++++ 14 files changed, 129 insertions(+), 98 deletions(-) delete mode 100644 composables/calculateTitle.ts delete mode 100644 composables/provideGlobal.ts create mode 100644 composables/useGlobal.ts rename composables/{calculateSitemap.ts => useSitemap.ts} (54%) create mode 100644 plugins/global.ts create mode 100644 plugins/sitemap.ts diff --git a/app.vue b/app.vue index f4b9fe0..c8080a2 100644 --- a/app.vue +++ b/app.vue @@ -3,19 +3,13 @@ diff --git a/components/Footer.vue b/components/Footer.vue index b92195f..967da90 100644 --- a/components/Footer.vue +++ b/components/Footer.vue @@ -29,7 +29,6 @@ diff --git a/components/Header.vue b/components/Header.vue index 5973b3e..22cf62c 100644 --- a/components/Header.vue +++ b/components/Header.vue @@ -64,8 +64,6 @@ diff --git a/components/base/ListImageItem.vue b/components/base/ListImageItem.vue index fc4ac3b..432d2e5 100644 --- a/components/base/ListImageItem.vue +++ b/components/base/ListImageItem.vue @@ -4,10 +4,10 @@ :class="allowNavigation ? '' : 'pointer-events-none'" :to="`${urlOverwrite ?? $route.path}/${data?.slug}`" > -
+
@@ -20,11 +20,11 @@
-
+

{{ data?.title }}

-

+

{{ itemDate }}

@@ -42,7 +42,7 @@ import type Lookup from "../../types/collection/lookup"; const runtimeConfig = useRuntimeConfig(); const baseUrl = runtimeConfig.public.strapi.url; -const { logo } = await provideGlobal(); +const { logo } = useGlobal(); const props = defineProps({ data: Object as PropType, diff --git a/components/shared/EmphasiseArticle.vue b/components/shared/EmphasiseArticle.vue index ade964f..8d99d1e 100644 --- a/components/shared/EmphasiseArticle.vue +++ b/components/shared/EmphasiseArticle.vue @@ -25,7 +25,7 @@ import type SharedEmphasiseArticle from "../../types/component/shared/emphasiseA import type Lookup from "../../types/collection/lookup"; const { find } = useStrapi(); -const { data: lookup } = await useAsyncData("lookup", () => +const { data: lookup } = await useAsyncData(() => find("collection-lookups", { filters: { collection: "articles", diff --git a/components/shared/List.vue b/components/shared/List.vue index 40b2348..b04ce21 100644 --- a/components/shared/List.vue +++ b/components/shared/List.vue @@ -113,13 +113,13 @@ const pagination = ref({ page: 0, pageSize: 0, pageCount: 0, total: 0 }); const activeYear = ref(0); if (props.data?.lookup.list_with_date != "none") { - const { data: year } = await useAsyncData>("distinct-years", () => + const { data: year } = await useAsyncData>(() => $fetch(`${baseUrl}/api/custom/${props.data?.lookup.collection}/distinct-years`) ); years.value = year.value ?? []; activeYear.value = years.value[0] ?? 0; } -const { data: collections } = await useAsyncData("collection", () => +const { data: collections } = await useAsyncData(() => find(props.data?.lookup.collection ?? "", { ...(props.data?.lookup?.list_with_date != "none" ? { @@ -235,7 +235,7 @@ async function changeTimedData(year: number) { withCount: true, }, }); - console.log(data); + collection.value = data?.data; pagination.value = (data?.meta.pagination as unknown as { page: number; diff --git a/composables/calculateTitle.ts b/composables/calculateTitle.ts deleted file mode 100644 index 2b9ab75..0000000 --- a/composables/calculateTitle.ts +++ /dev/null @@ -1,11 +0,0 @@ -import provideGlobal from "./provideGlobal"; - -export default async function () { - const runtimeConfig = useRuntimeConfig(); - const appTitle = runtimeConfig.public.app.title; - - const { SEO } = await provideGlobal(); - const { metaTitle } = SEO ?? {}; - - return metaTitle ?? appTitle; -} diff --git a/composables/provideGlobal.ts b/composables/provideGlobal.ts deleted file mode 100644 index 61beaf8..0000000 --- a/composables/provideGlobal.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type Global from "../types/single/global"; - -export default async function () { - const { findOne } = useStrapi(); - const { data: global } = await useAsyncData("global", () => findOne("global")); - const { logo, navbar, footer, SEO } = global.value?.data ?? {}; - - return { logo, navbar, footer, SEO }; -} diff --git a/composables/useGlobal.ts b/composables/useGlobal.ts new file mode 100644 index 0000000..922c1f5 --- /dev/null +++ b/composables/useGlobal.ts @@ -0,0 +1,26 @@ +import type BaseFile from "../types/component/baseFile"; +import type Footer from "../types/component/global/footer"; +import type Navbar from "../types/component/global/navbar"; +import type SEO from "../types/component/global/seo"; +import type Global from "../types/single/global"; + +export const useGlobal = () => { + const global = useState("global"); + const runtimeConfig = useRuntimeConfig(); + const appTitle = runtimeConfig.public.app.title; + + const logo = computed(() => global.value?.logo ?? null); + const navbar = computed(() => global.value?.navbar ?? null); + const footer = computed