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

75 lines
1.9 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 Feed from '../components/Feed';
import Page from '../components/Page';
2018-11-11 12:19:06 +01:00
import Pagination from '../components/Pagination';
2019-05-09 15:57:42 +02:00
import { useSiteMetadata } from '../hooks';
2019-05-10 01:15:43 +02:00
import type { PageContext, AllMarkdownRemark } from '../types';
2018-11-09 18:08:48 +01:00
2019-05-10 01:15:43 +02:00
type Props = {
data: AllMarkdownRemark,
pageContext: PageContext
};
const CategoryTemplate = ({ data, pageContext }: Props) => {
2019-05-09 15:57:42 +02:00
const { title: siteTitle, subtitle: siteSubtitle } = useSiteMetadata();
2018-11-09 18:08:48 +01:00
const {
category,
2018-11-11 12:19:06 +01:00
currentPage,
prevPagePath,
nextPagePath,
hasPrevPage,
hasNextPage,
2018-11-09 18:08:48 +01:00
} = pageContext;
const { edges } = data.allMarkdownRemark;
2018-11-11 12:19:06 +01:00
const pageTitle = currentPage > 0 ? `${category} - Page ${currentPage} - ${siteTitle}` : `${category} - ${siteTitle}`;
2018-11-09 18:08:48 +01:00
return (
<Layout title={pageTitle} description={siteSubtitle}>
<Sidebar />
<Page title={category}>
<Feed edges={edges} />
2018-11-11 12:19:06 +01:00
<Pagination
prevPagePath={prevPagePath}
nextPagePath={nextPagePath}
hasPrevPage={hasPrevPage}
hasNextPage={hasNextPage}
/>
2018-11-09 18:08:48 +01:00
</Page>
</Layout>
);
};
export const query = graphql`
2018-11-11 12:19:06 +01:00
query CategoryPage($category: String, $postsLimit: Int!, $postsOffset: Int!) {
2018-11-09 18:08:48 +01:00
allMarkdownRemark(
2018-11-11 12:19:06 +01:00
limit: $postsLimit,
skip: $postsOffset,
2018-11-11 17:32:51 +01:00
filter: { frontmatter: { category: { eq: $category }, template: { eq: "post" }, draft: { ne: true } } },
2018-11-09 18:08:48 +01:00
sort: { order: DESC, fields: [frontmatter___date] }
){
edges {
node {
fields {
categorySlug
slug
}
frontmatter {
date
description
category
title
}
}
}
}
}
`;
export default CategoryTemplate;