-
Notifications
You must be signed in to change notification settings - Fork 1
/
SEO.svelte
84 lines (82 loc) · 2.81 KB
/
SEO.svelte
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<script>
import { page } from "$app/stores";
export let title = "", description = "", keywords = "", canonical = "", siteName = "", imageURL = "", logo = "",
author = "", name = "";
export let index = true, twitter = true, openGraph = true;
export let schemaOrg = false;
export let socials = [];
let Ld = {
"@context": "https://schema.org",
"@type": ['Person', 'Organization'],
"name": `${name}`,
"url": `${$page.url.origin}`,
"image": `${imageURL}`,
logo: {
"@type": "ImageObject",
"url": `${logo}`,
"width": 48,
"height": 48
},
"sameAs": [
`${socials.join(", ")}`
]
};
let jsonLdScript = `<script type="application/ld+json">${JSON.stringify(Ld)}${'<'}/script>`;
</script>
<svelte:head>
{#if title !== ""}
{#if imageURL}
<meta name="robots" content={index ? "index, follow, max-image-preview:large" : "noindex"}>
{:else}
<meta name="robots" content={index ? "index, follow" : "noindex"}>
{/if}
<title>{title}</title>
<link rel="canonical" content="{canonical === '' ? $page.url : canonical}">
{/if}
{#if description !== ""}
<meta name="description" content="{description}">
{/if}
{#if keywords !== ""}
<meta name="keywords" content="{keywords}">
{/if}
{#if author !== ""}
<meta name="author" content="{author}">
{/if}
{#if openGraph}
{#if siteName !== ""}
<meta property="og:site_name" content="{siteName}">
{/if}
{#if title !== ""}
<meta property="og:url" content="{$page.url}">
<meta property="og:type" content="website">
<meta property="og:title" content="{title}">
{/if}
{#if description !== ""}
<meta property="og:description" content="{description}">
{/if}
{#if imageURL !== ""}
<meta property="og:image" content="{imageURL}">
{/if}
{#if logo !== ""}
<meta property="og:logo" content="{logo}">
{/if}
{/if}
{#if twitter}
{#if title !== ""}
<meta name="twitter:card" content="summary_large_image">
<meta property="twitter:domain" content="{$page.url.host}">
<meta property="twitter:url" content="{$page.url}">
<meta name="twitter:title" content="{title}">
{/if}
{#if description !== ""}
<meta name="twitter:description" content="{description}">
{/if}
{#if imageURL !== ""}
<meta name="twitter:image" content="{imageURL}">
{/if}
{/if}
<slot/>
{#if schemaOrg || socials[0] !== undefined || logo !== "" || name !== ""}
{@html jsonLdScript}
{/if}
</svelte:head>