-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathtutorial.js
More file actions
95 lines (85 loc) · 2.67 KB
/
tutorial.js
File metadata and controls
95 lines (85 loc) · 2.67 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React from 'react';
import { graphql, Link } from 'gatsby';
import { useIntl } from 'react-intl';
import { getImage } from 'gatsby-plugin-image';
import classnames from 'classnames';
import { MDXRenderer } from 'gatsby-plugin-mdx';
import HeadMatter from '../../components/HeadMatter';
import Layout from '../../components/Layout';
import Content from '../../components/ContentWithSidebar';
import { SidebarTableOfContents } from '../../components/Sidebar';
import Breadcrumbs from '../../components/Breadcrumbs';
import { useHighlight, useSidebar } from '../../hooks';
import { useTrail } from '../../hooks/tutorials';
import * as css from '../../styles/pages/page.module.css';
import * as grid from '../../styles/grid.module.css';
const TutorialTemplate = ({ data, pageContext }) => {
const { mdx } = data;
const [showSidebar, setShowSidebar] = useSidebar('tutorials');
const intl = useIntl();
useHighlight();
const trail = useTrail();
return (
<Layout withSidebar withBreadcrumbs>
<HeadMatter
title={mdx?.frontmatter.title}
description={mdx?.frontmatter.intro}
img={getImage(mdx?.frontmatter.coverImage)}
/>
<div className={classnames(grid.grid, css.root)}>
{mdx?.tableOfContents?.items && (
<SidebarTableOfContents
items={mdx.tableOfContents.items}
title={intl.formatMessage({ id: 'tableOfContents' })}
setShow={setShowSidebar}
show={showSidebar}
/>
)}
{mdx !== null ? (
<Content sidebarOpen={showSidebar}>
<Breadcrumbs trail={trail} />
<h1>{mdx.frontmatter.title}</h1>
<p className={css.author}>{`${intl.formatMessage({ id: 'by' })} ${
mdx.frontmatter.author
}`}</p>
<div className={css.content}>
<MDXRenderer>{mdx.body}</MDXRenderer>
</div>
</Content>
) : (
<Content sidebarOpen={showSidebar}>
{intl.formatMessage({ id: 'notTranslated' })}
<Link to={pageContext.slug}>
{' '}
{intl.formatMessage({ id: 'englishPage' })}
</Link>
</Content>
)}
</div>
</Layout>
);
};
export default TutorialTemplate;
export const query = graphql`
query($locale: String!, $slug: String!) {
mdx(
fields: { locale: { eq: $locale } }
frontmatter: { slug: { eq: $slug } }
) {
body
frontmatter {
title
slug
author
level
intro
coverImage {
childImageSharp {
gatsbyImageData(width: 600)
}
}
}
tableOfContents
}
}
`;