|
1 | 1 | <script> |
2 | | - let { title = '', description = '', ogImage = '', ogType = 'website', canonical = '' } = $props() |
| 2 | + import { page } from '$app/state' |
| 3 | +
|
| 4 | + let { |
| 5 | + title = '', |
| 6 | + description = '', |
| 7 | + ogImage = '', |
| 8 | + ogType = 'website', |
| 9 | + canonical = '', |
| 10 | + jsonLd = null, |
| 11 | + } = $props() |
| 12 | +
|
3 | 13 | const siteName = 'PostGuard' |
4 | | - const defaultDescription = 'PostGuard offers free and easy-to-use end-to-end encryption for emails and files.' |
| 14 | + const siteUrl = 'https://postguard.eu' |
| 15 | + const defaultDescription = |
| 16 | + 'PostGuard offers free and easy-to-use end-to-end encryption for emails and files.' |
5 | 17 | const defaultImage = '/pg_logo.png' |
| 18 | +
|
| 19 | + const canonicalUrl = $derived( |
| 20 | + canonical || (page?.url?.pathname ? `${siteUrl}${page.url.pathname}` : '') |
| 21 | + ) |
| 22 | + const ogImageUrl = $derived( |
| 23 | + (ogImage || defaultImage).startsWith('http') |
| 24 | + ? ogImage || defaultImage |
| 25 | + : `${siteUrl}${ogImage || defaultImage}` |
| 26 | + ) |
| 27 | + const jsonLdString = $derived(jsonLd ? JSON.stringify(jsonLd) : '') |
6 | 28 | </script> |
7 | 29 |
|
8 | 30 | <svelte:head> |
9 | 31 | <title>{title ? `${title} | ${siteName}` : siteName}</title> |
10 | 32 | <meta name="description" content={description || defaultDescription} /> |
11 | 33 | <meta property="og:title" content={title || siteName} /> |
12 | 34 | <meta property="og:description" content={description || defaultDescription} /> |
13 | | - <meta property="og:image" content={ogImage || defaultImage} /> |
| 35 | + <meta property="og:image" content={ogImageUrl} /> |
14 | 36 | <meta property="og:type" content={ogType} /> |
15 | 37 | <meta property="og:site_name" content={siteName} /> |
16 | | - {#if canonical}<link rel="canonical" href={canonical} />{/if} |
| 38 | + {#if canonicalUrl} |
| 39 | + <meta property="og:url" content={canonicalUrl} /> |
| 40 | + <link rel="canonical" href={canonicalUrl} /> |
| 41 | + <link rel="alternate" hreflang="en" href={canonicalUrl} /> |
| 42 | + <link rel="alternate" hreflang="nl" href={canonicalUrl} /> |
| 43 | + <link rel="alternate" hreflang="x-default" href={canonicalUrl} /> |
| 44 | + {/if} |
17 | 45 | <meta name="twitter:card" content="summary_large_image" /> |
| 46 | + <meta name="twitter:title" content={title || siteName} /> |
| 47 | + <meta name="twitter:description" content={description || defaultDescription} /> |
| 48 | + <meta name="twitter:image" content={ogImageUrl} /> |
| 49 | + {#if jsonLdString} |
| 50 | + {@html `<script type="application/ld+json">${jsonLdString}<\/script>`} |
| 51 | + {/if} |
18 | 52 | </svelte:head> |
0 commit comments