rickvanlieshout.com/src/templates/page-template.js
2019-07-31 22:05:23 -04:00

47 lines
1.2 KiB
JavaScript

// @flow strict
import React from 'react';
import { graphql } from 'gatsby';
import Layout from '../components/Layout';
import Sidebar from '../components/Sidebar';
import Page from '../components/Page';
import { useSiteMetadata } from '../hooks';
import type { MarkdownRemark } from '../types';
type Props = {
data: {
markdownRemark: MarkdownRemark
}
};
const PageTemplate = ({ data }: Props) => {
const { title: siteTitle, subtitle: siteSubtitle } = useSiteMetadata();
const { html: pageBody } = data.markdownRemark;
const { title: pageTitle, description: pageDescription } = data.markdownRemark.frontmatter;
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!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
id
html
frontmatter {
title
date
description
}
}
}
`;
export default PageTemplate;