1
|
|
|
import React from "react" |
2
|
|
|
import { graphql, Link } from "gatsby" |
3
|
|
|
import Layout from "../layouts/index" |
4
|
|
|
import SEO from "../components/seo" |
5
|
|
|
import Img from "gatsby-image" |
6
|
|
|
|
7
|
|
|
import Share from "../components/share" |
8
|
|
|
|
9
|
|
|
import "./article.scss" |
10
|
|
|
|
11
|
|
|
// eslint-disable-next-line |
12
|
|
|
String.prototype.replaceAll = function (search, replacement) { |
13
|
|
|
var target = this |
14
|
|
|
return target.replace(new RegExp(search, "g"), replacement) |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
export default ({ data }) => { |
18
|
|
|
const post = data.nodeArticle |
19
|
|
|
|
20
|
|
|
const { |
21
|
|
|
site: { |
22
|
|
|
siteMetadata: { siteUrl, twitterHandle }, |
23
|
|
|
}, |
24
|
|
|
} = data |
25
|
|
|
|
26
|
|
|
const aspectRatio = |
27
|
|
|
post.relationships.field_media_article_image.relationships.field_media_image |
28
|
|
|
.localFile.childImageSharp.fluid |
29
|
|
|
|
30
|
|
|
const image = ( |
31
|
|
|
<Img |
32
|
|
|
fluid={{ |
33
|
|
|
...post.relationships.field_media_article_image.relationships |
34
|
|
|
.field_media_image.localFile.childImageSharp.fluid, |
35
|
|
|
aspectRatio: aspectRatio > 1 ? 2.5 / 1 : 1.5 / 1, |
36
|
|
|
}} |
37
|
|
|
alt={post.title} |
38
|
|
|
/> |
39
|
|
|
) |
40
|
|
|
|
41
|
|
|
const ogImage = { |
42
|
|
|
src: |
43
|
|
|
post.relationships.field_media_article_image.relationships |
44
|
|
|
.field_media_image.localFile.childImageSharp.resize.src, |
45
|
|
|
width: |
46
|
|
|
post.relationships.field_media_article_image.relationships |
47
|
|
|
.field_media_image.localFile.childImageSharp.resize.width, |
48
|
|
|
height: |
49
|
|
|
post.relationships.field_media_article_image.relationships |
50
|
|
|
.field_media_image.localFile.childImageSharp.resize.height, |
51
|
|
|
} |
52
|
|
|
const relatedArticles = post.relationships.field_related_content || [] |
53
|
|
|
const relatedTags = post.relationships.field_tags || [] |
54
|
|
|
const cleanBody = post.body.processed.replaceAll( |
55
|
|
|
"/sites/default/", |
56
|
|
|
`${process.env.GATSBY_API_DOMAIN}/sites/default/` |
57
|
|
|
) |
58
|
|
|
|
59
|
|
|
const pathUrl = post.path.alias |
60
|
|
|
|
61
|
|
|
return ( |
62
|
|
|
<Layout> |
63
|
|
|
<SEO |
64
|
|
|
lang="nl-BE" |
65
|
|
|
title={post.title} |
66
|
|
|
description={post.body.summary} |
67
|
|
|
path={pathUrl} |
68
|
|
|
image={ogImage} |
69
|
|
|
/> |
70
|
|
|
|
71
|
|
|
<article className={"article__wrapper"}> |
72
|
|
|
<header className={"article__header"}> |
73
|
|
|
<figure className={"article__header_image"}> |
74
|
|
|
{image} |
75
|
|
|
<div className={"gradient gradient--70"}></div> |
76
|
|
|
</figure> |
77
|
|
|
<h3 className={"article__header__heading"}> |
78
|
|
|
<span>{post.title}</span> |
79
|
|
|
</h3> |
80
|
|
|
</header> |
81
|
|
|
<main className={"article__body"}> |
82
|
|
|
<section className={"article__metadata container clearfix"}> |
83
|
|
|
<div className={"article__author"}> |
84
|
|
|
Geschreven door {post.relationships.uid.display_name}. |
85
|
|
|
</div> |
86
|
|
|
<div className={"article__tags"}> |
87
|
|
|
<span className={"datetime"}> |
88
|
|
|
<i className={"fa fa-clock-o"} aria-hidden="true"></i>{" "} |
89
|
|
|
{post.created} |
90
|
|
|
</span> |
91
|
|
|
{relatedTags.length > 0 && ( |
92
|
|
|
<span className={"tag__wrapper"}> |
93
|
|
|
<i className={"fa fa-tags"} aria-hidden="true"></i>{" "} |
94
|
|
|
{relatedTags.map(({ path, name }, i) => ( |
95
|
|
|
<Link to={path.alias} key={i}> |
96
|
|
|
<span key={i} className={"tag__label"}> |
97
|
|
|
#{name} |
98
|
|
|
</span> |
99
|
|
|
</Link> |
100
|
|
|
))} |
101
|
|
|
</span> |
102
|
|
|
)} |
103
|
|
|
</div> |
104
|
|
|
<div className={"article__social-share"}> |
105
|
|
|
<Share |
106
|
|
|
socialConfig={{ |
107
|
|
|
twitterHandle, |
108
|
|
|
config: { |
109
|
|
|
url: `${siteUrl}${post.path.alias}`, |
110
|
|
|
title: post.title, |
111
|
|
|
}, |
112
|
|
|
}} |
113
|
|
|
tags={relatedTags} |
114
|
|
|
/> |
115
|
|
|
</div> |
116
|
|
|
</section> |
117
|
|
|
<section> |
118
|
|
|
<div dangerouslySetInnerHTML={{ __html: cleanBody }} /> |
119
|
|
|
</section> |
120
|
|
|
</main> |
121
|
|
|
<footer className={"article__footer__wrapper"}> |
122
|
|
|
<section className={"article__footer"}> |
123
|
|
|
{relatedArticles.length > 0 && ( |
124
|
|
|
<> |
125
|
|
|
<h3>Gerelateerde inhoud</h3> |
126
|
|
|
{relatedArticles.map(({ path, title, internal }, i) => { |
127
|
|
|
return ( |
128
|
|
|
<article key={i} className={"article__footer_related"}> |
129
|
|
|
<i |
130
|
|
|
className={`article__footer_related__icon article__footer_related__icon--${internal.type} fa`} |
131
|
|
|
/> |
132
|
|
|
<Link to={path.alias}>{title}</Link> |
133
|
|
|
</article> |
134
|
|
|
) |
135
|
|
|
})} |
136
|
|
|
</> |
137
|
|
|
)} |
138
|
|
|
</section> |
139
|
|
|
</footer> |
140
|
|
|
</article> |
141
|
|
|
</Layout> |
142
|
|
|
) |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
export const query = graphql` |
146
|
|
|
query($slug: String!) { |
147
|
|
|
site { |
148
|
|
|
siteMetadata { |
149
|
|
|
siteUrl |
150
|
|
|
twitterHandle |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
nodeArticle(path: { alias: { eq: $slug } }) { |
154
|
|
|
path { |
155
|
|
|
alias |
156
|
|
|
} |
157
|
|
|
created(formatString: "DD/MM/YYYY") |
158
|
|
|
body { |
159
|
|
|
processed |
160
|
|
|
summary |
161
|
|
|
} |
162
|
|
|
title |
163
|
|
|
relationships { |
164
|
|
|
uid { |
165
|
|
|
display_name |
166
|
|
|
} |
167
|
|
|
field_related_content { |
168
|
|
|
... on node__article { |
169
|
|
|
title |
170
|
|
|
path { |
171
|
|
|
alias |
172
|
|
|
} |
173
|
|
|
internal { |
174
|
|
|
type |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
... on node__player { |
178
|
|
|
title |
179
|
|
|
path { |
180
|
|
|
alias |
181
|
|
|
} |
182
|
|
|
internal { |
183
|
|
|
type |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
... on node__staff { |
187
|
|
|
title |
188
|
|
|
path { |
189
|
|
|
alias |
190
|
|
|
} |
191
|
|
|
internal { |
192
|
|
|
type |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
... on node__team { |
196
|
|
|
title |
197
|
|
|
path { |
198
|
|
|
alias |
199
|
|
|
} |
200
|
|
|
internal { |
201
|
|
|
type |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
field_media_article_image { |
206
|
|
|
...ArticleImage |
207
|
|
|
} |
208
|
|
|
field_tags { |
209
|
|
|
name |
210
|
|
|
path { |
211
|
|
|
alias |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
` |
218
|
|
|
|