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

49 lines
1.3 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-08-25 14:15:37 +02:00
const { frontmatter } = data.markdownRemark;
2019-08-25 13:50:36 +02:00
const { title: pageTitle, description: pageDescription, socialImage } = frontmatter;
2018-11-09 18:08:48 +01:00
const metaDescription = pageDescription !== null ? pageDescription : siteSubtitle;
return (
2019-08-25 12:29:51 +02:00
<Layout title={`${pageTitle} - ${siteTitle}`} description={metaDescription} socialImage={socialImage} >
2018-11-09 18:08:48 +01:00
<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
2019-08-25 12:29:51 +02:00
socialImage
2018-11-09 18:08:48 +01:00
}
}
}
`;
export default PageTemplate;