2018-05-23 21:47:54 +02:00
|
|
|
import React from 'react'
|
2018-06-21 22:32:56 +02:00
|
|
|
import { StaticQuery, graphql } from 'gatsby'
|
2018-05-23 21:47:54 +02:00
|
|
|
import Helmet from 'react-helmet'
|
|
|
|
|
2018-06-21 22:32:56 +02:00
|
|
|
const TypekitScript = typekitID => (
|
2018-05-23 21:47:54 +02:00
|
|
|
<script>
|
|
|
|
{`
|
|
|
|
(function(d) {
|
|
|
|
var config = {
|
2018-06-21 22:32:56 +02:00
|
|
|
kitId: '${typekitID}',
|
2018-05-23 21:47:54 +02:00
|
|
|
scriptTimeout: 3000,
|
|
|
|
async: true
|
|
|
|
},
|
|
|
|
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
|
|
|
|
})(document);
|
|
|
|
`}
|
|
|
|
</script>
|
|
|
|
)
|
|
|
|
|
2018-06-21 22:32:56 +02:00
|
|
|
const Typekit = () => (
|
|
|
|
<StaticQuery
|
|
|
|
query={graphql`
|
2018-07-11 15:54:32 +02:00
|
|
|
query {
|
2018-06-21 22:32:56 +02:00
|
|
|
dataYaml {
|
|
|
|
typekitID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
render={data => {
|
|
|
|
const { typekitID } = data.dataYaml
|
|
|
|
|
|
|
|
return (
|
|
|
|
typekitID && (
|
|
|
|
<Helmet>
|
|
|
|
<link rel="dns-prefetch" href="https://use.typekit.net/" />
|
|
|
|
<link rel="dns-prefetch" href="https://p.typekit.net/" />
|
2018-05-23 21:47:54 +02:00
|
|
|
|
2018-06-21 22:32:56 +02:00
|
|
|
{TypekitScript(typekitID)}
|
|
|
|
</Helmet>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
/>
|
2018-05-23 21:47:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
export default Typekit
|