-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
head-function-export.js
70 lines (64 loc) · 1.68 KB
/
head-function-export.js
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
import * as React from "react"
import { useStaticQuery, graphql } from "gatsby"
import { data } from "../../shared-data/head-function-export.js"
function HeadComponent({ children }) {
const data = useStaticQuery(graphql`
query SiteMetaDataStaticQuery {
site {
siteMetadata {
headFunctionExport {
base
title
meta
noscript
style
link
}
}
}
}
`)
const { base, title, meta, noscript, style, link } =
data?.site?.siteMetadata?.headFunctionExport || {}
return (
<>
<base data-testid="base" href={base} />
<title data-testid="title">{title}</title>
<meta data-testid="meta" name="author" content={meta} />
<noscript data-testid="noscript">{noscript}</noscript>
<style data-testid="style">
{`
h1 {
color: ${style};
}
`}
</style>
<link data-testid="link" href={link} rel="stylesheet" />
{children}
</>
)
}
function Head() {
const { base, title, meta, noscript, style, link, jsonLD } = data.static
return (
<>
<base data-testid="base" href={base} />
<title data-testid="title">{title}</title>
<meta data-testid="meta" name="author" content={meta} />
<noscript data-testid="noscript">{noscript}</noscript>
<style data-testid="style">
{`
h1 {
color: ${style};
}
`}
</style>
<link data-testid="link" href={link} rel="stylesheet" />
<script data-testid="jsonLD" type="application/ld+json">
{jsonLD}
</script>
</>
)
}
export { Head }
export default HeadComponent