Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit d7fb579

Browse files
committed
404 page fixes
1 parent 4d7ba00 commit d7fb579

File tree

2 files changed

+138
-6
lines changed

2 files changed

+138
-6
lines changed

src/layouts/root.jsx

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import React from 'react';
2+
import styled from '@emotion/styled';
3+
import { ThemeProvider, Global } from '@emotion/react';
4+
import Helmet from 'react-helmet';
5+
import { graphql } from 'gatsby';
6+
import { transitions, positions, Provider as AlertProvider } from 'react-alert'
7+
8+
import lightTheme from '../themes';
9+
import styles from '../styles';
10+
11+
import Header from '../components/header';
12+
13+
14+
const RootDiv = styled.div`
15+
width: 100vw;
16+
height: 100vh;
17+
`;
18+
19+
20+
const AlertContainer = styled.div`
21+
border-radius: 32px;
22+
overflow: hidden;
23+
background-color: ${props => props.theme.notificationBackground};
24+
color: ${props => props.theme.notificationTextPrimary};
25+
padding: 16px 32px 16px 32px;
26+
font-size: 1em;
27+
`;
28+
29+
30+
const AlertTemplate = ({ style, options, message, close }) => (
31+
<AlertContainer style={style}>
32+
{message}
33+
</AlertContainer>
34+
)
35+
36+
37+
const alertOptions = {
38+
position: positions.BOTTOM_CENTER,
39+
timeout: 3000,
40+
offset: '24px',
41+
transition: transitions.FADE,
42+
};
43+
44+
45+
const Root = ({ data, pageContext }) => {
46+
const isDocsPage = data && data.mdx;
47+
const metaTitle = data && data.mdx ? data.mdx.frontmatter.metaTitle : null;
48+
const metaDescription = data && data.mdx ? data.mdx.frontmatter.metaDescription : null;
49+
console.log(pageContext);
50+
51+
return (
52+
<RootDiv>
53+
<Helmet>
54+
{metaTitle ? <title>{metaTitle}</title> : null}
55+
{metaTitle ? <meta name="title" content={metaTitle} /> : null}
56+
{metaDescription ? <meta name="description" content={metaDescription} /> : null}
57+
{metaTitle ? <meta property="og:title" content={metaTitle} /> : null}
58+
{metaDescription ? <meta property="og:description" content={metaDescription} /> : null}
59+
{metaTitle ? <meta property="twitter:title" content={metaTitle} /> : null}
60+
{metaDescription ? (
61+
<meta property="twitter:description" content={metaDescription} />
62+
) : null}
63+
</Helmet>
64+
<ThemeProvider theme={lightTheme}>
65+
<AlertProvider template={AlertTemplate} {...alertOptions}>
66+
<Global styles={styles} />
67+
<Header />
68+
{isDocsPage ?
69+
<DocsLayout mdxFields={data.mdx.fields}
70+
mdxFrontMatter={data.mdx.frontmatter}
71+
mdxTOC={data.mdx.tableOfContents}
72+
allMdx={data.allMdx}>
73+
{data.mdx.body}
74+
</DocsLayout>: ""}
75+
</AlertProvider>
76+
</ThemeProvider>
77+
</RootDiv>
78+
);
79+
}
80+
81+
export default Root;
82+
83+
export const pageQuery = graphql`
84+
query($id: String!) {
85+
site {
86+
siteMetadata {
87+
title
88+
docsLocation
89+
}
90+
}
91+
mdx(fields: { id: { eq: $id } }) {
92+
fields {
93+
id
94+
title
95+
slug
96+
}
97+
body
98+
tableOfContents
99+
parent {
100+
... on File {
101+
relativePath
102+
}
103+
}
104+
frontmatter {
105+
metaTitle
106+
metaDescription
107+
githubURL
108+
index
109+
skipToChild
110+
}
111+
}
112+
allMdx {
113+
edges {
114+
node {
115+
fields {
116+
id
117+
slug
118+
title
119+
}
120+
frontmatter {
121+
index
122+
targetURL
123+
skipToChild
124+
metaTitle
125+
metaDescription
126+
}
127+
}
128+
}
129+
}
130+
}
131+
`;

src/root.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ const alertOptions = {
4444

4545

4646
const Root = ({ data, pageContext }) => {
47-
// meta tags
48-
const metaTitle = data.mdx.frontmatter.metaTitle;
49-
const metaDescription = data.mdx.frontmatter.metaDescription;
47+
const isDocsPage = data && data.mdx;
48+
const metaTitle = data && data.mdx ? data.mdx.frontmatter.metaTitle : null;
49+
const metaDescription = data && data.mdx ? data.mdx.frontmatter.metaDescription : null;
5050

5151
return (
5252
<RootDiv>
@@ -65,12 +65,13 @@ const Root = ({ data, pageContext }) => {
6565
<AlertProvider template={AlertTemplate} {...alertOptions}>
6666
<Global styles={styles} />
6767
<Header />
68-
<DocsLayout mdxFields={data.mdx.fields}
68+
{isDocsPage ?
69+
<DocsLayout mdxFields={data.mdx.fields}
6970
mdxFrontMatter={data.mdx.frontmatter}
7071
mdxTOC={data.mdx.tableOfContents}
7172
allMdx={data.allMdx}>
72-
{data.mdx.body}
73-
</DocsLayout>
73+
{data.mdx.body}
74+
</DocsLayout>: ""}
7475
</AlertProvider>
7576
</ThemeProvider>
7677
</RootDiv>

0 commit comments

Comments
 (0)