Skip to content

Commit

Permalink
refactor: move google head tags to gatsby-ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Sep 19, 2022
1 parent f374cba commit 0a9b448
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
15 changes: 0 additions & 15 deletions website/gatsby-ssr.ts

This file was deleted.

40 changes: 40 additions & 0 deletions website/gatsby-ssr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/

import React, { Fragment } from 'react'

import { GatsbySSR } from 'gatsby'

const GoogleAdsTag = (
<script
key="google-ads"
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5817566022458684"
crossOrigin="anonymous"
/>
)

const GoogleFontTag = (
<Fragment key="google-fonts">
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="true"
/>
<link
href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400&family=Fira+Sans:wght@300;400;700&display=swap"
rel="stylesheet"
/>
</Fragment>
)

export const onRenderBody: GatsbySSR['onRenderBody'] = props => {
props.setHtmlAttributes({ lang: 'en' })
props.setHeadComponents([GoogleAdsTag, GoogleFontTag])
}

export { default as wrapPageElement } from './src/libs/wrapPageElement'
17 changes: 0 additions & 17 deletions website/src/components/seo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ const SEO: FC<SEOProps> = ({ title = '', description = '', children }) => {
<meta property="og:url" content={seo.url} />

{children}

<script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5817566022458684"
crossOrigin="anonymous"
></script>

<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="true"
/>
<link
href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400&family=Fira+Sans:wght@300;400;700&display=swap"
rel="stylesheet"
/>
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
}
},

"include": ["./src/**/*", "./gatsby-*.ts"],
"include": ["src/**/*", "gatsby-*.ts", "gatsby-ssr.tsx"],
"exclude": ["node_modules", "public", ".cache", "generated"]
}

0 comments on commit 0a9b448

Please sign in to comment.