-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
45 lines (41 loc) · 1.2 KB
/
gatsby-ssr.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
import * as React from 'react'
import {
PrismicPreviewProvider,
componentResolverFromMap,
} from 'gatsby-plugin-prismic-previews'
import { PrismicProvider } from '@prismicio/react'
import { Link as GatsbyLink } from 'gatsby'
import { linkResolver } from './src/utils/linkResolver'
import PageTemplate from './src/pages/page'
/**
* An adapter to support Gatsby's `<Link>` component when using `<PrismicLink>`.
*/
const GatsbyLinkShim = React.forwardRef(({ href, ...props }, ref) => {
return <GatsbyLink to={href} ref={ref} {...props} />
})
GatsbyLinkShim.displayName = 'GatsbyLinkShim'
export const wrapRootElement = ({ element }) => (
<PrismicProvider
linkResolver={linkResolver}
internalLinkComponent={GatsbyLinkShim}
>
<PrismicPreviewProvider
repositoryConfigs={[
{
repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
linkResolver,
componentResolver: componentResolverFromMap({
page: PageTemplate,
}),
},
]}
>
{element}
</PrismicPreviewProvider>
</PrismicProvider>
)
export const onRenderBody = ({ setHtmlAttributes }, pluginOptions) => {
setHtmlAttributes({
className: 'bg-gray-50',
})
}