2022-01-09 20:12:31 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { graphql } from "gatsby";
|
|
|
|
|
|
|
|
import { Feed } from "@/components/Feed";
|
|
|
|
import { Layout } from "@/components/Layout";
|
|
|
|
import { Page } from "@/components/Page";
|
|
|
|
import { Pagination } from "@/components/Pagination";
|
|
|
|
import { Sidebar } from "@/components/Sidebar";
|
|
|
|
import { useSiteMetadata } from "@/hooks";
|
|
|
|
import { AllMarkdownRemark, PageContext } from "@/types";
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
data: {
|
|
|
|
allMarkdownRemark: AllMarkdownRemark;
|
|
|
|
};
|
|
|
|
pageContext: PageContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CategoryTemplate: React.FC<Props> = ({ data, pageContext }: Props) => {
|
|
|
|
const { title: siteTitle, subtitle: siteSubtitle } = useSiteMetadata();
|
|
|
|
|
|
|
|
const { group, pagination } = pageContext;
|
|
|
|
const { currentPage, prevPagePath, nextPagePath, hasPrevPage, hasNextPage } =
|
|
|
|
pagination;
|
|
|
|
|
|
|
|
const { edges } = data.allMarkdownRemark;
|
|
|
|
const pageTitle =
|
|
|
|
currentPage > 0
|
|
|
|
? `${group} - Page ${currentPage} - ${siteTitle}`
|
|
|
|
: `${group} - ${siteTitle}`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Layout title={pageTitle} description={siteSubtitle}>
|
|
|
|
<Sidebar />
|
|
|
|
<Page title={group}>
|
|
|
|
<Feed edges={edges} />
|
|
|
|
<Pagination
|
|
|
|
prevPagePath={prevPagePath}
|
|
|
|
nextPagePath={nextPagePath}
|
|
|
|
hasPrevPage={hasPrevPage}
|
|
|
|
hasNextPage={hasNextPage}
|
|
|
|
/>
|
|
|
|
</Page>
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const query = graphql`
|
2022-04-16 14:25:55 +00:00
|
|
|
query CategoryTemplate($group: String, $limit: Int!, $offset: Int!) {
|
2022-01-09 20:12:31 +00:00
|
|
|
allMarkdownRemark(
|
2022-04-16 14:25:55 +00:00
|
|
|
limit: $limit
|
|
|
|
skip: $offset
|
2022-01-09 20:12:31 +00:00
|
|
|
filter: {
|
|
|
|
frontmatter: {
|
2022-04-16 14:25:55 +00:00
|
|
|
category: { eq: $group }
|
2022-01-09 20:12:31 +00:00
|
|
|
template: { eq: "post" }
|
|
|
|
draft: { ne: true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort: { order: DESC, fields: [frontmatter___date] }
|
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
categorySlug
|
|
|
|
}
|
|
|
|
frontmatter {
|
|
|
|
description
|
|
|
|
category
|
|
|
|
title
|
|
|
|
date
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default CategoryTemplate;
|