2018-07-25 07:47:26 -04:00
|
|
|
import React from 'react';
|
2020-04-20 10:15:49 +03:00
|
|
|
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';
|
2021-03-08 01:29:06 -08:00
|
|
|
import DocsTemplate from '../components/docs-template';
|
2018-07-25 07:47:26 -04:00
|
|
|
|
2020-02-19 16:55:10 -05:00
|
|
|
function filenameFromPath(p) {
|
2021-05-19 14:39:35 +02:00
|
|
|
return p.split('/').slice(-1)[0].split('.')[0];
|
2020-02-19 16:55:10 -05:00
|
|
|
}
|
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function toMenu(menu, nav) {
|
|
|
|
return menu.map(group => ({
|
2018-07-25 07:47:26 -04:00
|
|
|
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
|
|
|
}));
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
2018-07-25 07:47:26 -04:00
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function DocPage({ data, location }) {
|
2020-02-20 16:38:34 +01: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
|
|
|
);
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
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;
|