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

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-08-01 04:05:23 +02:00
// @flow strict
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';
2019-05-10 01:15:43 +02:00
import type { MarkdownRemark } from '../types';
2018-11-09 18:08:48 +01:00
2019-05-10 01:15:43 +02:00
type Props = {
data: {
markdownRemark: MarkdownRemark
}
};
const PageTemplate = ({ data }: Props) => {
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!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
id
html
frontmatter {
title
date
description
}
}
}
`;
export default PageTemplate;