import React from 'react';
import Helmet from 'react-helmet';
import { matchPath } from 'react-router-dom';
import EditLink from '../components/edit-link';
import Widgets from '../components/widgets';
import DocsNav from '../components/docs-nav';
import MobileNav from '../components/mobile-nav';
import '../css/lib/prism.css';
import '../css/imports/docs.css';
const toMenu = (menu, nav) =>
menu.map(group => ({
title: group.title,
group: nav.group.find(g => g.fieldValue === group.name),
}));
const DocPage = ({ data, location, history }) => {
const { nav, page, widgets, menu } = data;
const docsNav = toMenu(menu.siteMetadata.menu.docs, nav);
const showWidgets = matchPath(location.pathname, { path: '/docs/widgets' });
return (
{page.frontmatter.title}
{showWidgets && }
);
};
export const pageQuery = graphql`
query docPage($slug: String!) {
page: markdownRemark(fields: { slug: { eq: $slug } }) {
fields {
path
}
frontmatter {
title
}
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 }
filter: { frontmatter: { label: { ne: null } }, fields: { slug: { regex: "/widgets/" } } }
) {
edges {
node {
frontmatter {
label
target
}
html
}
}
}
}
`;
export default DocPage;