2018-07-25 07:47:26 -04:00
|
|
|
import React from 'react';
|
|
|
|
import Helmet from 'react-helmet';
|
2018-08-23 17:58:38 -04:00
|
|
|
import { graphql } from 'gatsby';
|
2018-10-01 20:00:57 -04:00
|
|
|
import 'prismjs/themes/prism-tomorrow.css';
|
2018-07-25 07:47:26 -04:00
|
|
|
|
2018-08-23 17:58:38 -04:00
|
|
|
import Layout from '../components/layout';
|
2018-07-25 07:47:26 -04:00
|
|
|
import DocsNav from '../components/docs-nav';
|
2020-01-23 21:55:18 -05:00
|
|
|
import Container from '../components/container';
|
|
|
|
import SidebarLayout from '../components/sidebar-layout';
|
2020-02-19 16:55:10 -05:00
|
|
|
import EditLink from '../components/edit-link';
|
|
|
|
import Widgets from '../components/widgets';
|
2020-01-23 21:55:18 -05:00
|
|
|
import Markdown from '../components/markdown';
|
2018-07-25 07:47:26 -04:00
|
|
|
|
2020-02-19 16:55:10 -05:00
|
|
|
function filenameFromPath(p) {
|
|
|
|
return p.split('/').slice(-1)[0].split('.')[0];
|
|
|
|
}
|
|
|
|
|
2018-07-25 07:47:26 -04:00
|
|
|
const toMenu = (menu, nav) =>
|
|
|
|
menu.map(group => ({
|
|
|
|
title: group.title,
|
2018-08-07 14:46:54 -06:00
|
|
|
group: nav.group.find(g => g.fieldValue === group.name),
|
2018-07-25 07:47:26 -04:00
|
|
|
}));
|
|
|
|
|
2020-01-23 21:55:18 -05:00
|
|
|
const DocsSidebar = ({ docsNav, location }) => (
|
|
|
|
<aside>
|
2018-09-06 14:44:58 -04:00
|
|
|
<DocsNav items={docsNav} location={location} />
|
|
|
|
</aside>
|
|
|
|
);
|
|
|
|
|
|
|
|
export const DocsTemplate = ({
|
|
|
|
title,
|
2020-02-19 16:55:10 -05:00
|
|
|
filename,
|
2018-09-06 14:44:58 -04:00
|
|
|
body,
|
|
|
|
html,
|
|
|
|
showWidgets,
|
|
|
|
widgets,
|
|
|
|
showSidebar,
|
|
|
|
docsNav,
|
|
|
|
location,
|
2020-02-19 16:55:10 -05:00
|
|
|
group,
|
2018-09-06 14:44:58 -04:00
|
|
|
}) => (
|
2020-01-23 21:55:18 -05:00
|
|
|
<Container size="md">
|
|
|
|
<SidebarLayout
|
2020-02-19 16:55:10 -05:00
|
|
|
sidebar={showSidebar && <DocsSidebar docsNav={docsNav} location={location} />}
|
2020-01-23 21:55:18 -05:00
|
|
|
>
|
|
|
|
<article data-docs-content>
|
2020-02-19 16:55:10 -05:00
|
|
|
{filename && (
|
|
|
|
<EditLink collection={`docs_${group}`} filename={filename} />
|
|
|
|
)}
|
2018-09-06 14:44:58 -04:00
|
|
|
<h1>{title}</h1>
|
2020-02-19 16:55:10 -05:00
|
|
|
<Markdown body={body} html={html} />
|
2018-09-06 14:44:58 -04:00
|
|
|
{showWidgets && <Widgets widgets={widgets} />}
|
|
|
|
</article>
|
2020-01-23 21:55:18 -05:00
|
|
|
</SidebarLayout>
|
|
|
|
</Container>
|
2018-09-06 14:44:58 -04:00
|
|
|
);
|
|
|
|
|
2020-01-23 21:55:18 -05:00
|
|
|
const DocPage = ({ data, location }) => {
|
2020-02-19 16:55:10 -05:00
|
|
|
const { nav, page: { frontmatter, html, fields }, widgets, menu } = data;
|
|
|
|
const { title, group } = frontmatter
|
2018-07-25 07:47:26 -04:00
|
|
|
|
|
|
|
const docsNav = toMenu(menu.siteMetadata.menu.docs, nav);
|
2018-08-23 17:58:38 -04:00
|
|
|
const showWidgets = location.pathname.indexOf('/docs/widgets') !== -1;
|
2020-02-19 16:55:10 -05:00
|
|
|
const filename = filenameFromPath(fields.path);
|
2018-07-25 07:47:26 -04:00
|
|
|
|
|
|
|
return (
|
2018-08-23 17:58:38 -04:00
|
|
|
<Layout>
|
2020-02-19 16:55:10 -05:00
|
|
|
<Helmet title={title} />
|
2018-09-06 14:44:58 -04:00
|
|
|
<DocsTemplate
|
2020-02-19 16:55:10 -05:00
|
|
|
title={title}
|
|
|
|
filename={filename}
|
|
|
|
html={html}
|
2018-09-06 14:44:58 -04:00
|
|
|
showWidgets={showWidgets}
|
|
|
|
widgets={widgets}
|
|
|
|
docsNav={docsNav}
|
|
|
|
location={location}
|
2020-02-19 16:55:10 -05:00
|
|
|
group={group}
|
2018-09-06 14:44:58 -04:00
|
|
|
showSidebar
|
|
|
|
/>
|
2018-08-23 17:58:38 -04:00
|
|
|
</Layout>
|
2018-07-25 07:47:26 -04:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const pageQuery = graphql`
|
|
|
|
query docPage($slug: String!) {
|
|
|
|
page: markdownRemark(fields: { slug: { eq: $slug } }) {
|
|
|
|
fields {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
frontmatter {
|
|
|
|
title
|
2020-02-19 16:55:10 -05:00
|
|
|
group
|
2018-07-25 07:47:26 -04:00
|
|
|
}
|
|
|
|
html
|
|
|
|
}
|
|
|
|
nav: allMarkdownRemark(
|
|
|
|
sort: { fields: [frontmatter___weight], order: ASC }
|
|
|
|
filter: {
|
|
|
|
frontmatter: { title: { ne: null }, group: { ne: null } }
|
|
|
|
fields: { slug: { regex: "/docs/" } }
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
group(field: frontmatter___group) {
|
|
|
|
fieldValue
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
frontmatter {
|
|
|
|
title
|
|
|
|
group
|
|
|
|
}
|
|
|
|
tableOfContents
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu: site {
|
|
|
|
siteMetadata {
|
|
|
|
menu {
|
|
|
|
docs {
|
|
|
|
name
|
|
|
|
title
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
widgets: allMarkdownRemark(
|
|
|
|
sort: { fields: [frontmatter___label], order: ASC }
|
2018-08-07 14:46:54 -06:00
|
|
|
filter: { frontmatter: { label: { ne: null } }, fields: { slug: { regex: "/widgets/" } } }
|
2018-07-25 07:47:26 -04:00
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
frontmatter {
|
2018-10-01 20:00:57 -04:00
|
|
|
title
|
2018-07-25 07:47:26 -04:00
|
|
|
label
|
|
|
|
}
|
|
|
|
html
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default DocPage;
|