rickvanlieshout.com/src/templates/page-template.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-11-09 18:08:48 +01:00
import React from 'react';
import { graphql } from 'gatsby';
import Layout from '../components/Layout';
import Sidebar from '../components/Sidebar';
import Page from '../components/Page';
2019-05-09 15:57:42 +02:00
import { useSiteMetadata } from '../hooks';
2018-11-09 18:08:48 +01:00
const PageTemplate = ({ data }) => {
2019-05-09 15:57:42 +02:00
const { title: siteTitle, subtitle: siteSubtitle } = useSiteMetadata();
2018-11-09 18:08:48 +01:00
const { html: pageBody } = data.markdownRemark;
2019-05-09 15:57:42 +02:00
const { title: pageTitle, description: pageDescription } = data.markdownRemark.frontmatter;
2018-11-09 18:08:48 +01:00
const metaDescription = pageDescription !== null ? pageDescription : siteSubtitle;
return (
<Layout title={`${pageTitle} - ${siteTitle}`} description={metaDescription}>
<Sidebar />
<Page title={pageTitle}>
<div dangerouslySetInnerHTML={{ __html: pageBody }} />
</Page>
</Layout>
);
};
export const query = graphql`
query PageBySlug($slug: String!) {
site {
siteMetadata {
title
subtitle
}
}
markdownRemark(fields: { slug: { eq: $slug } }) {
id
html
frontmatter {
title
date
description
}
}
}
`;
export default PageTemplate;