1
|
|
|
import { PageQuery } from "../Types/Page" |
2
|
|
|
import { Seo } from "../components/Seo" |
3
|
|
|
import Layout from "../layouts" |
4
|
|
|
import { graphql } from "gatsby" |
5
|
|
|
import { GatsbyImage, getImage, getSrc } from "gatsby-plugin-image" |
6
|
|
|
import React from "react" |
7
|
|
|
|
8
|
|
|
const PageTemplate = ({ data }: PageQuery) => { |
9
|
|
|
const post = data.nodePage |
10
|
|
|
const image = |
11
|
|
|
post.relationships?.field_media_article_image?.relationships?.field_media_image?.localFile?.childImageSharp |
12
|
|
|
?.gatsbyImageData && |
13
|
|
|
getImage( |
14
|
|
|
post.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp |
15
|
|
|
.gatsbyImageData |
16
|
|
|
) |
17
|
|
|
|
18
|
|
|
// Convert links to paths on our API, to absolute URL's. |
19
|
|
|
const cleanBody = post.body.processed.replaceAll(`/sites/default/`, `${process.env.GATSBY_API_DOMAIN}/sites/default/`) |
20
|
|
|
|
21
|
|
|
return ( |
22
|
|
|
<Layout> |
23
|
|
|
<header className="page_header__wrapper"> |
24
|
|
|
<div className="page_header"> |
25
|
|
|
<h1>{post.title}</h1> |
26
|
|
|
</div> |
27
|
|
|
</header> |
28
|
|
|
|
29
|
|
|
{image && ( |
30
|
|
|
<div className="page__header__image__wrapper"> |
31
|
|
|
<div className="page__header__image__bg"> |
32
|
|
|
<GatsbyImage image={image} alt={``} /> |
33
|
|
|
</div> |
34
|
|
|
<div className="page__header__image__hero"> |
35
|
|
|
<GatsbyImage image={image} alt={``} /> |
36
|
|
|
</div> |
37
|
|
|
</div> |
38
|
|
|
)} |
39
|
|
|
<main className="page__wrapper page__wrapper--limited"> |
40
|
|
|
<div dangerouslySetInnerHTML={{ __html: cleanBody }} className="page__body" /> |
41
|
|
|
</main> |
42
|
|
|
</Layout> |
43
|
|
|
) |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
export const Head = ({ data }: PageQuery) => { |
47
|
|
|
const post = data.nodePage |
48
|
|
|
const image = getImage( |
49
|
|
|
post.relationships?.image_og?.relationships?.field_media_image?.localFile?.childImageSharp?.gatsbyImageData |
50
|
|
|
) |
51
|
|
|
const ogImage = image && { |
52
|
|
|
src: getSrc(image) || ``, |
53
|
|
|
width: image.width, |
54
|
|
|
height: image.height, |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
const pathUrl = post.path.alias |
58
|
|
|
return <Seo title={post.title} path={pathUrl} image={ogImage} /> |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
export const query = graphql` |
62
|
|
|
query ($slug: String!) { |
63
|
|
|
nodePage(path: { alias: { eq: $slug } }) { |
64
|
|
|
path { |
65
|
|
|
alias |
66
|
|
|
} |
67
|
|
|
body { |
68
|
|
|
processed |
69
|
|
|
} |
70
|
|
|
title |
71
|
|
|
relationships { |
72
|
|
|
field_media_article_image { |
73
|
|
|
...HeroImage |
74
|
|
|
} |
75
|
|
|
image_og: field_media_article_image { |
76
|
|
|
...ArticleImage |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
` |
82
|
|
|
|
83
|
|
|
export default PageTemplate |
84
|
|
|
|