-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSEO.svelte
More file actions
59 lines (55 loc) · 2.07 KB
/
Copy pathSEO.svelte
File metadata and controls
59 lines (55 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script>
import { page } from '$app/state'
import { SITE_URL } from '$lib/env'
let {
title = '',
description = '',
ogImage = '',
ogType = 'website',
canonical = '',
jsonLd = null,
} = $props()
const siteName = 'PostGuard'
const defaultDescription =
'PostGuard offers free and easy-to-use end-to-end encryption for emails and files.'
const defaultImage = '/pg_logo.png'
const canonicalUrl = $derived(
canonical ||
(page?.url?.pathname ? `${SITE_URL}${page.url.pathname}` : '')
)
const ogImageUrl = $derived(
(ogImage || defaultImage).startsWith('http')
? ogImage || defaultImage
: `${SITE_URL}${ogImage || defaultImage}`
)
const jsonLdString = $derived(jsonLd ? JSON.stringify(jsonLd) : '')
</script>
<svelte:head>
<title>{title ? `${title} | ${siteName}` : siteName}</title>
<meta name="description" content={description || defaultDescription} />
<meta property="og:title" content={title || siteName} />
<meta
property="og:description"
content={description || defaultDescription}
/>
<meta property="og:image" content={ogImageUrl} />
<meta property="og:type" content={ogType} />
<meta property="og:site_name" content={siteName} />
{#if canonicalUrl}
<meta property="og:url" content={canonicalUrl} />
<link rel="canonical" href={canonicalUrl} />
<link rel="alternate" hreflang="en" href={canonicalUrl} />
<link rel="alternate" hreflang="x-default" href={canonicalUrl} />
{/if}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={title || siteName} />
<meta
name="twitter:description"
content={description || defaultDescription}
/>
<meta name="twitter:image" content={ogImageUrl} />
{#if jsonLdString}
<!-- eslint-disable-next-line svelte/no-at-html-tags, no-useless-escape -->
{@html `<script type="application/ld+json">${jsonLdString}<\/script>`}
{/if}
</svelte:head>