1
0
Fork 0
blog/src/components/templates/Archive.tsx

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-05-22 14:38:19 +02:00
import React, { ReactElement } from 'react'
2020-07-19 13:31:27 +02:00
import { graphql } from 'gatsby'
import { PageContext } from '../../@types/Post'
2020-03-04 22:21:12 +01:00
import Pagination from '../molecules/Pagination'
2020-07-19 13:31:27 +02:00
import PostTeaser from '../molecules/PostTeaser'
import Page from './Page'
import * as styles from './Archive.module.css'
2018-07-17 23:33:55 +02:00
2020-07-08 01:31:03 +02:00
export default function Archive({
2019-10-02 13:35:50 +02:00
data,
pageContext
}: {
data: Queries.ArchiveTemplateQuery
2020-07-19 13:31:27 +02:00
pageContext: PageContext
2020-05-22 14:38:19 +02:00
}): ReactElement {
2018-07-17 23:33:55 +02:00
const edges = data.allMarkdownRemark.edges
2019-11-06 20:44:33 +01:00
const { tag, currentPageNumber, numPages } = pageContext
2018-07-22 04:27:37 +02:00
const PostsList = edges.map(({ node }) => (
2020-07-19 13:31:27 +02:00
<PostTeaser key={node.id} post={node} />
))
2018-07-22 04:27:37 +02:00
2020-07-19 13:31:27 +02:00
const title = tag ? `#${tag}` : 'Archive'
2018-07-22 04:27:37 +02:00
2020-07-19 13:31:27 +02:00
const paginationTitle =
numPages > 1 && currentPageNumber > 1
? `Page ${currentPageNumber} / ${numPages}`
: ''
2018-07-22 04:27:37 +02:00
2020-07-19 13:31:27 +02:00
const page = {
frontmatter: {
title: `${title} ${paginationTitle}`,
description: 'All the articles & links.'
}
}
2018-07-22 04:27:37 +02:00
2018-09-06 20:27:18 +02:00
return (
2021-03-07 02:48:05 +01:00
<Page
title={page.frontmatter.title}
post={page}
pathname={pageContext.slug}
>
<div className={styles.posts}>{PostsList}</div>
2019-11-06 20:44:33 +01:00
{numPages > 1 && <Pagination pageContext={pageContext} />}
2020-07-19 13:31:27 +02:00
</Page>
2018-09-06 20:27:18 +02:00
)
2018-07-17 23:33:55 +02:00
}
2020-07-08 01:31:03 +02:00
export const archiveQuery = graphql`
query ArchiveTemplate($tag: String, $skip: Int, $limit: Int) {
2018-09-04 02:57:39 +02:00
allMarkdownRemark(
2021-02-28 04:50:05 +01:00
filter: {
2021-03-16 00:13:01 +01:00
fields: { type: { nin: "photo" } }
2021-02-28 04:50:05 +01:00
frontmatter: { tags: { eq: $tag } }
}
sort: { fields: { date: DESC } }
2018-09-04 02:57:39 +02:00
skip: $skip
limit: $limit
) {
2018-07-17 23:33:55 +02:00
edges {
node {
2020-07-19 13:31:27 +02:00
...PostTeaser
2018-07-17 23:33:55 +02:00
}
}
}
}
`