This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
gatsby-ssr.js
63 lines (56 loc) · 1.64 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import PageLayout from './src/components/PageLayout';
import React from 'react';
import {
DOCS_PAGE_WIDTH_VAR,
PAGE_JUMBO_WIDTH,
PAGE_NORMAL_WIDTH
} from './src/components/PageWidthContext';
import {withPrefix} from 'gatsby';
export const wrapPageElement = ({element, props}) => (
<PageLayout {...props}>{element}</PageLayout>
);
const headComponents = [
<script
key="extend-fix"
dangerouslySetInnerHTML={{
__html: `
const pageWidth = JSON.parse(localStorage.getItem('page-width') ?? "\\"normal\\"");
const PAGE_NORMAL_WIDTH = ${PAGE_NORMAL_WIDTH};
const PAGE_JUMBO_WIDTH = ${PAGE_JUMBO_WIDTH};
const pageWidthPx = (pageWidth === 'normal' ? PAGE_NORMAL_WIDTH : PAGE_JUMBO_WIDTH) + 'px';
const root = document.querySelector(':root');
root.style.setProperty('${DOCS_PAGE_WIDTH_VAR}', pageWidthPx);
`
}}
/>,
<style
key="font-face"
dangerouslySetInnerHTML={{
__html: `
@font-face {
font-family: "Aeonik";
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(${withPrefix(
'/fonts/aeonik/Aeonik-Medium.woff2'
)}) format("woff2");
}
`
}}
/>
];
if (process.env.CONTEXT === 'production') {
headComponents.push(
<script
key="qualified-js"
id="qualified-js"
async
src="https://js.qualified.com/qualified.js?token=mdpGqx2V2oJXA51Q" // gitleaks:allow
/>
);
}
export const onRenderBody = ({setHeadComponents, setHtmlAttributes}) => {
setHeadComponents(headComponents);
setHtmlAttributes({lang: 'en'});
};