Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update meta tags in layout and mod page #184

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { page } from '$app/stores'; // Importing this enables dynamic handling of <meta> tags

import LoginDialog from '$lib/components/auth/LoginDialog.svelte';
import { setContextClient } from '@urql/svelte';
import { onMount } from 'svelte';
Expand All @@ -16,7 +18,13 @@
import { computePosition, autoUpdate, offset, shift, flip, arrow } from '@floating-ui/dom';

export let data: LayoutData;

// Using the $page store, this script supplies default metadeta
const defaultMeta = {
title: 'Satisfactory Mod Repository',
description: 'Your source for mods!',
image: '/assets/favicon.ico',
url: $page.url.origin + $page.url.pathname
};
const { client, tolgee } = data;

initializeStores();
Expand Down Expand Up @@ -83,6 +91,7 @@
</script>

<svelte:head>
<!-- STATIC head elements that don't change across page nav -->
<link rel="icon" type="image/x-icon" href="{base}/assets/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="{base}/assets/apple-touch-icon.png?v=69P26YMB35" />
<link rel="icon" type="image/png" sizes="32x32" href="{base}/assets/favicon-32x32.png?v=69P26YMB35" />
Expand All @@ -96,6 +105,15 @@

<link rel="preload" href="{base}/assets/fonts/flow-rounded.woff" as="font" type="font/woff" />

<!-- Ensure the meta tags are only rendered if no duplication occurs -->
<!-- Title and meta tags dynamically controlled by page data or default values -->
<title>{$page.data.meta?.title || defaultMeta.title} - SMR</title>
<meta name="description" content={$page.data.meta?.description || defaultMeta.description} />
<meta property="og:title" content="{$page.data.meta?.title || defaultMeta.title} - SMR" />
<meta property="og:description" content={$page.data.meta?.description || defaultMeta.description} />
<meta property="og:image" content={$page.data.meta?.image || defaultMeta.image} />
<meta property="og:url" content={$page.data.meta?.url || defaultMeta.url} />

{#if gTag}
<script async src="https://www.googletagmanager.com/gtag/js?id={gTag}"></script>
<script>
Expand Down
7 changes: 6 additions & 1 deletion src/routes/mod/[modId]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ export const load: PageLoad = async ({ params, parent }) => ({
client: (await parent()).client,
variables: { mod: params.modId }
})
}))
})),
meta: {
title: 'Mods',
description: 'Mods available from the Satisfactory Mod Repository',
image: '/assets/favicon.ico'
}
});