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

68 lines
1.7 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 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';
2018-11-09 18:08:48 +01:00
const CategoryTemplate = ({ data, pageContext }) => {
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;