-
Notifications
You must be signed in to change notification settings - Fork 5
/
+layout.svelte
180 lines (153 loc) · 3.84 KB
/
+layout.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
date: 2023-07-11T12:28:44.499Z
updated: 2023-07-11T12:28:45.984Z
---
<script lang="ts">
import Header from '$lib/components/organisms/Header.svelte';
import Footer from '$lib/components/organisms/Footer.svelte';
import Tag from '$lib/components/atoms/Tag.svelte';
import dateformat from 'dateformat';
import { keywords, siteBaseUrl, title } from '$lib/data/meta';
import type { BlogPost } from '$lib/utils/types';
import RelatedPosts from '$lib/components/organisms/RelatedPosts.svelte';
import Image from '$lib/components/atoms/Image.svelte';
export let data: { post: BlogPost };
$: ({ post } = data);
let metaKeywords = keywords;
$: {
if (post?.tags?.length) {
metaKeywords = post.tags.concat(metaKeywords);
}
if (post?.keywords?.length) {
metaKeywords = post.keywords.concat(metaKeywords);
}
}
</script>
<svelte:head>
{#if post}
<meta name="keywords" content={metaKeywords.join(', ')} />
<meta name="description" content={post.excerpt} />
<meta property="og:description" content={post.excerpt} />
<meta name="twitter:description" content={post.excerpt} />
<link rel="canonical" href="{siteBaseUrl}/{post.slug}" />
<title>{post.title} - {title}</title>
<meta property="og:title" content="{post.title} - {title}" />
<meta name="twitter:title" content="{post.title} - {title}" />
{#if post.coverImage}
<meta property="og:image" content="{siteBaseUrl}{post.coverImage}" />
<meta name="twitter:image" content="{siteBaseUrl}{post.coverImage}" />
{/if}
{/if}
</svelte:head>
<div class="article-layout">
<Header showBackground />
<main>
<article id="article-content">
<div class="header">
{#if post}
<h1>{post.title}</h1>
<div class="note">Published on {dateformat(post.date, 'UTC:dd mmmm yyyy')}</div>
{#if post.updated}
<div class="note">Updated on {dateformat(post.updated, 'UTC:dd mmmm yyyy')}</div>
{/if}
{#if post.readingTime}
<div class="note">{post.readingTime}</div>
{/if}
{#if post.tags?.length}
<div class="tags">
{#each post.tags as tag}
<Tag>{tag}</Tag>
{/each}
</div>
{/if}
{/if}
</div>
{#if post && post.coverImage}
<div class="cover-image">
<Image src={post.coverImage} alt={post.title} />
</div>
{/if}
<div class="content">
<slot />
</div>
</article>
{#if post.relatedPosts && post.relatedPosts.length > 0}
<div class="container">
<RelatedPosts posts={post.relatedPosts} />
</div>
{/if}
</main>
<Footer />
</div>
<style lang="scss">
@import '$lib/scss/_mixins.scss';
.article-layout {
--body-background-color: var(--color--post-page-background);
background-color: var(--color--post-page-background);
}
#article-content {
position: relative;
padding-top: 40px;
padding-bottom: 80px;
padding-right: 15px;
padding-left: 15px;
@include for-iphone-se {
padding-left: 0;
padding-right: 0;
}
@include for-tablet-portrait-up {
padding-right: 20px;
padding-left: 20px;
}
@include for-tablet-landscape-up {
padding-right: 30px;
padding-left: 30px;
}
display: grid;
grid-template-columns:
1fr
min(65ch, 100%)
1fr;
grid-row-gap: 30px;
> * {
grid-column: 2;
}
.full-bleed {
width: 100%;
grid-column: 1 / 4;
}
.header {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
gap: 10px;
.note {
font-size: 90%;
color: rgba(var(--color--text-rgb), 0.8);
}
}
.cover-image {
width: 100%;
max-height: 400px;
box-shadow: var(--image-shadow);
border-radius: 6px;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
}
:global(.cover-image img) {
object-fit: cover;
}
.tags {
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
flex-wrap: wrap;
}
}
</style>