rickvanlieshout.com/src/templates/categories-list-template.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-11-09 18:08:48 +01:00
import React from 'react';
import { Link, graphql } from 'gatsby';
import kebabCase from 'lodash/kebabCase';
import Sidebar from '../components/Sidebar';
import Layout from '../components/Layout';
import Page from '../components/Page';
const CategoriesListTemplate = ({ data }) => {
const {
title,
subtitle
} = data.site.siteMetadata;
const { group } = data.allMarkdownRemark;
return (
<Layout title={`Categories - ${title}`} description={subtitle}>
<Sidebar />
<Page title="Categories">
<ul>
{group.map((category) => (
<li key={category.fieldValue}>
<Link to={`/categories/${kebabCase(category.fieldValue)}/`}>
{category.fieldValue} ({category.totalCount})
</Link>
</li>
))}
</ul>
</Page>
</Layout>
);
};
export const query = graphql`
query CategoriesListQuery {
site {
siteMetadata {
title
subtitle
}
}
allMarkdownRemark(
filter: { frontmatter: { layout: { eq: "post" }, draft: { ne: true } } }
) {
group(field: frontmatter___category) {
fieldValue
totalCount
}
}
}
`;
export default CategoriesListTemplate;