import React from 'react'
import { css, Global } from '@emotion/core'
import { graphql, useStaticQuery } from 'gatsby'
import { Helmet } from 'react-helmet'
import generic from '@styles/generic'
import prism from '@styles/prism'
import styled from '@components/styled'
interface Props {
children: React.ReactNode
title?: string | null
description?: string | null
image?: string | null
url?: string | null
noIndex?: boolean
}
const globalCss = css`
${generic}
${prism}
`
const query = graphql`
query SiteTitleQuery {
site {
siteMetadata {
title
description
keywords
language
siteUrl
twitterHandle
}
}
portrait: file(relativePath: { eq: "img/author.png" }) {
childImageSharp {
fixed(width: 200, height: 200) {
src
}
}
}
}
`
const imageUrl = (base: string, path: string | null) => {
if (!path) return null
return `${base}${path}`
}
const Main = styled.main`
margin: 0 auto;
width: ${({ theme }) => theme.sizes.container}px;
max-width: 100%;
padding: 40px 20px;
position: relative;
`
export default function Layout({ children, title: customTitle = '', description: customDescription, image, url, noIndex }: Props) {
const { site, portrait } = useStaticQuery(query)
const { title, description, keywords, language, siteUrl, twitterHandle } = site.siteMetadata
const metaImage = imageUrl(siteUrl, image || portrait?.childImageSharp.fixed.src)
const currentUrl = `${siteUrl}${url && '/'}${url || ''}`
return (
<>