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

65 lines
1.4 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';
const CategoryTemplate = ({ data, pageContext }) => {
const {
title: siteTitle,
subtitle: siteSubtitle
} = data.site.siteMetadata;
const {
category,
page
} = pageContext;
const { edges } = data.allMarkdownRemark;
const pageTitle = page > 0 ? `${category} - Page ${page} - ${siteTitle}` : `${category} - ${siteTitle}`;
return (
<Layout title={pageTitle} description={siteSubtitle}>
<Sidebar />
<Page title={category}>
<Feed edges={edges} />
</Page>
</Layout>
);
};
export const query = graphql`
query CategoryPage($category: String, $limit: Int!, $skip: Int!) {
site {
siteMetadata {
title
subtitle
}
}
allMarkdownRemark(
limit: $limit,
skip: $skip,
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;