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';
|
2018-11-09 18:08:48 +01:00
|
|
|
|
|
|
|
const CategoryTemplate = ({ data, pageContext }) => {
|
|
|
|
const {
|
|
|
|
title: siteTitle,
|
|
|
|
subtitle: siteSubtitle
|
|
|
|
} = data.site.siteMetadata;
|
|
|
|
|
|
|
|
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
|
|
|
site {
|
|
|
|
siteMetadata {
|
|
|
|
title
|
|
|
|
subtitle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
allMarkdownRemark(
|
2018-11-11 12:19:06 +01:00
|
|
|
limit: $postsLimit,
|
|
|
|
skip: $postsOffset,
|
2018-11-09 18:08:48 +01:00
|
|
|
filter: { frontmatter: { category: { eq: $category }, layout: { eq: "post" }, draft: { ne: true } } },
|
|
|
|
sort: { order: DESC, fields: [frontmatter___date] }
|
|
|
|
){
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
categorySlug
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
frontmatter {
|
|
|
|
date
|
|
|
|
description
|
|
|
|
category
|
|
|
|
title
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default CategoryTemplate;
|