generated from maehr/github-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Head.svelte
158 lines (140 loc) · 4.41 KB
/
Head.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<script>
import * as config from '$lib/config';
import { page } from '$app/stores';
export let title = config.title + ' ' + config.subtitle;
export let keywords = config.keywords;
export let description = config.description;
export let author = config.author;
export let canonical = config.url + $page.url.pathname;
export let image = '/android-chrome-512x512.png';
export let imageWidth = '512';
export let imageHeight = '512';
export let jsonLdDataType = 'WebSite';
export let jsonLdData = {};
export let date = '';
export let modified = '';
export let excerpt = '';
function generateStructuredData(type) {
const websiteData = {
'@type': 'WebSite',
name: config.title,
url: config.url,
logo: config.url + '/android-chrome-512x512.png',
sameAs: [
'https://www.instagram.com/' + config.instagramHandle,
'https://www.linkedin.com/company/' + config.linkedinHandle,
'https://twitter.com/' + config.twitterHandle,
'https://github.com/' + config.githubHandle
]
};
if (type === 'WebSite') {
return {
'@context': 'https://schema.org',
...websiteData
};
}
let pageSpecificData = {};
switch (type) {
case 'Article':
pageSpecificData = {
'@type': 'Article',
headline: title,
datePublished: new Date(date).toUTCString(),
dateModified: new Date(modified).toUTCString(),
publisher: {
'@type': 'Organization',
name: config.title,
logo: config.url + '/android-chrome-512x512.png'
},
description: excerpt,
mainEntityOfPage: {
'@type': 'WebPage',
'@id': config.url + $page.url.pathname
}
};
break;
case 'BlogPosting':
pageSpecificData = {
'@type': 'BlogPosting',
headline: title,
datePublished: new Date(date).toUTCString(),
dateModified: new Date(modified).toUTCString(),
publisher: {
'@type': 'Organization',
name: config.title,
logo: config.url + '/android-chrome-512x512.png'
},
description: excerpt,
mainEntityOfPage: {
'@type': 'WebPage',
'@id': config.url + $page.url.pathname
},
image: {
'@type': 'ImageObject',
url: config.url + image,
width: imageWidth,
height: imageHeight
}
};
break;
case 'map':
pageSpecificData = {
'@type': 'Map'
// FIXME: Add map specific data
};
break;
case 'event':
pageSpecificData = {
'@type': 'Event'
// FIXME: Add event specific data
};
break;
default:
pageSpecificData = {};
}
return {
'@context': 'https://schema.org',
'@graph': [websiteData, pageSpecificData, jsonLdData]
};
}
let structuredData = generateStructuredData(jsonLdDataType);
let jsonLdString = JSON.stringify(structuredData);
</script>
<svelte:head>
<title>{title}</title>
<!-- General meta tags -->
<meta name="generator" content="gh:{config.githubHandle}/{config.githubRepo}" />
<meta name="keywords" content={keywords} />
<meta name="description" content={description} />
<meta name="author" content={author} />
<meta name="theme-color" content={config.themeColor} />
<!-- Canonical link -->
<link rel="canonical" href={canonical} />
<!-- Manifest link -->
<link rel="manifest" href="/manifest.webmanifest" />
<!-- RSS feed -->
<link rel="alternate" type="application/rss+xml" href="/rss.xml" />
<!-- Sitemap link -->
<link rel="sitemap" type="application/xml" href="/sitemap.xml" />
<!-- Twitter tags -->
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:site" content={config.twitterHandle} />
<meta name="twitter:creator" content={config.twitterHandle} />
<meta property="twitter:image" content={config.url + image} />
<meta property="twitter:image:width" content={imageWidth} />
<meta property="twitter:image:height" content={imageHeight} />
<!-- Open Graph / Facebook tags-->
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:url" content={config.url} />
<meta property="og:site_name" content={config.title} />
<meta property="og:type" content="website" />
<meta property="og:image" content={config.url + image} />
<meta property="og:image:width" content={imageWidth} />
<meta property="og:image:height" content={imageHeight} />
<!-- JSON-LD -->
<svelte:element this={'script'} type="application/ld+json">
{jsonLdString}
</svelte:element>
</svelte:head>