1
|
|
|
import React from "react" |
2
|
|
|
import { graphql } from "gatsby" |
3
|
|
|
import Layout from "../layouts/index" |
4
|
|
|
import SEO from "../components/seo" |
5
|
|
|
import Img from "gatsby-image" |
6
|
|
|
|
7
|
|
|
import "./article.scss" |
8
|
|
|
|
9
|
|
|
// eslint-disable-next-line |
10
|
|
|
String.prototype.replaceAll = function (search, replacement) { |
11
|
|
|
var target = this |
12
|
|
|
return target.replace(new RegExp(search, "g"), replacement) |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
export default ({ data }) => { |
16
|
|
|
const post = data.nodePage |
17
|
|
|
let image = null |
18
|
|
|
|
19
|
|
|
if (post.relationships.field_media_article_image) { |
20
|
|
|
const aspectRatio = |
21
|
|
|
post.relationships.field_media_article_image.relationships |
22
|
|
|
.field_media_image.localFile.childImageSharp.fluid |
23
|
|
|
|
24
|
|
|
// Create a fluid image based on its original aspectRatio. |
25
|
|
|
image = ( |
26
|
|
|
<Img |
27
|
|
|
fluid={{ |
28
|
|
|
...post.relationships.field_media_article_image.relationships |
29
|
|
|
.field_media_image.localFile.childImageSharp.fluid, |
30
|
|
|
aspectRatio: aspectRatio > 1 ? 1.7 / 1 : 2 / 1, |
31
|
|
|
}} |
32
|
|
|
alt={post.title} |
33
|
|
|
/> |
34
|
|
|
) |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// Convert links to paths on our API, to absolute URL's. |
38
|
|
|
const cleanBody = post.body.processed.replaceAll( |
39
|
|
|
"/sites/default/", |
40
|
|
|
`${process.env.GATSBY_API_DOMAIN}/sites/default/` |
41
|
|
|
) |
42
|
|
|
const pathUrl = post.path.alias |
43
|
|
|
|
44
|
|
|
return ( |
45
|
|
|
<Layout> |
46
|
|
|
<SEO lang="nl-BE" title={post.title} path={pathUrl} /> |
47
|
|
|
|
48
|
|
|
<article className={"article__wrapper"}> |
49
|
|
|
<header |
50
|
|
|
className={ |
51
|
|
|
"article__header" + (!image ? " article__header--no-image" : "") |
52
|
|
|
} |
53
|
|
|
> |
54
|
|
|
{image && ( |
55
|
|
|
<figure className={"article__header_image"}> |
56
|
|
|
{image} |
57
|
|
|
<div className={"gradient gradient--70"}></div> |
58
|
|
|
</figure> |
59
|
|
|
)} |
60
|
|
|
<h3 className={"article__header__heading"}> |
61
|
|
|
<span>{post.title}</span> |
62
|
|
|
</h3> |
63
|
|
|
</header> |
64
|
|
|
<main className={"article__body"}> |
65
|
|
|
<section> |
66
|
|
|
<div dangerouslySetInnerHTML={{ __html: cleanBody }} /> |
67
|
|
|
</section> |
68
|
|
|
</main> |
69
|
|
|
</article> |
70
|
|
|
</Layout> |
71
|
|
|
) |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
export const query = graphql` |
75
|
|
|
query($slug: String!) { |
76
|
|
|
nodePage(path: { alias: { eq: $slug } }) { |
77
|
|
|
path { |
78
|
|
|
alias |
79
|
|
|
} |
80
|
|
|
body { |
81
|
|
|
processed |
82
|
|
|
} |
83
|
|
|
title |
84
|
|
|
relationships { |
85
|
|
|
field_media_article_image { |
86
|
|
|
...ArticleImage |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
` |
92
|
|
|
|