Skip to content

Commit

Permalink
fix(app): conditionally access globals (#99)
Browse files Browse the repository at this point in the history
* conditionally access globals

* add some more conditional global access

* some more optional rendering for globals
  • Loading branch information
ComfortablyCoding authored Jul 30, 2024
1 parent 019fd3c commit 9abcfec
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/Logo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const appConfig = useAppConfig();
const logo = computed(() => {
return appConfig.globals.logo_on_dark_bg;
return appConfig.globals?.logo_on_dark_bg;
});
const props = defineProps({

Check warning on line 8 in components/Logo.vue

View workflow job for this annotation

GitHub Actions / Lint

'props' is assigned a value but never used. Allowed unused vars must match /^_/u
Expand Down
2 changes: 1 addition & 1 deletion components/navigation/MobileMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ watch(
<NuxtLink href="/">
<Logo class="h-6 dark:text-white" />
</NuxtLink>
<VText v-if="globals.tagline" class="pb-4 mt-2">
<VText v-if="globals?.tagline" class="pb-4 mt-2">
{{ globals.tagline }}
</VText>
</div>
Expand Down
8 changes: 5 additions & 3 deletions components/navigation/TheFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const { data: form } = await useAsyncData(
<NuxtLink href="/">
<Logo class="h-8 dark:text-white" />
</NuxtLink>
<VText v-if="globals.tagline" text-color="light" class="mt-2">
<VText v-if="globals?.tagline" text-color="light" class="mt-2">
{{ globals.tagline }}
</VText>
</div>
Expand Down Expand Up @@ -106,7 +106,7 @@ const { data: form } = await useAsyncData(
<div class="pt-6 mx-auto border-t dark:border-t-gray-700 max-w-7xl md:flex md:items-center md:justify-between">
<div class="flex items-center justify-center space-x-6 md:order-last md:mb-0">
<NuxtLink
v-for="link in globals.social_links"
v-for="link in globals?.social_links"
:key="link.url"
:href="link.url"
class="w-6 h-6 text-white"
Expand All @@ -119,7 +119,9 @@ const { data: form } = await useAsyncData(
<div class="mt-8 md:mt-0 md:order-1">
<span class="mt-2 text-gray-600 dark:text-gray-400">
Copyright © 1988 - {{ new Date().getFullYear() }}
<NuxtLink href="/" class="mx-2 hover:text-primary" rel="noopener noreferrer">{{ globals.title }}.</NuxtLink>
<NuxtLink v-if="globals?.title" href="/" class="mx-2 hover:text-primary" rel="noopener noreferrer">
{{ globals.title }}.
</NuxtLink>
All rights reserved.
</span>
<!-- You're free to remove this footer if you want. But we'd appreciate it if you keep the credits. -->
Expand Down
7 changes: 2 additions & 5 deletions components/navigation/TheHeader.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<script setup lang="ts">
const {
theme,
globals: { title },
} = useAppConfig();
const { theme, globals } = useAppConfig();
const {
data: navigation,
Expand Down Expand Up @@ -54,7 +51,7 @@ const {
<div class="flex items-center bg-gray-900 justify-between py-2 px-6 md:flex-1 rounded-card">
<NuxtLink href="/" class="py-2">
<Logo class="h-6 text-white" />
<span class="sr-only">{{ title }}</span>
<span v-if="globals?.title" class="sr-only">{{ globals.title }}</span>
</NuxtLink>
<nav class="hidden md:flex md:space-x-4 lg:space-x-6" aria-label="Global">
<NavigationMenuItem v-for="item in navigation?.items" :key="item.id" :item="item" />
Expand Down
2 changes: 1 addition & 1 deletion pages/[...permalink].vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const metadata = computed(() => {
return {
title: pageData?.seo?.title ?? pageData?.title ?? undefined,
description: pageData?.seo?.meta_description ?? pageData?.summary ?? undefined,
image: globals.og_image ? fileUrl(globals.og_image) : undefined,
image: globals?.og_image ? fileUrl(globals.og_image) : undefined,
canonical: pageData?.seo?.canonical_url ?? url,
};
});
Expand Down

0 comments on commit 9abcfec

Please sign in to comment.