import React, { ReactElement } from 'react' import { graphql } from 'gatsby' import { PageContext } from '../../@types/Post' import HeadMeta, { HeadMetaProps } from '../atoms/HeadMeta' import Pagination from '../molecules/Pagination' import PostTeaser from '../molecules/PostTeaser' import * as styles from './Archive.module.css' import Page from './Page' function getMetadata(pageContext: PageContext) { const { tag, currentPageNumber, numPages } = pageContext const title = tag ? `#${tag}` : 'Archive' const paginationTitle = numPages > 1 && currentPageNumber > 1 ? `Page ${currentPageNumber} / ${numPages}` : '' const meta: Partial = { title: `${title} ${paginationTitle}`, description: 'All the articles & links.' } return meta } export default function Archive({ data, pageContext }: { data: Queries.ArchiveTemplateQuery pageContext: PageContext }): ReactElement { const edges = data.allMarkdownRemark.edges const meta = getMetadata(pageContext) const PostsList = edges.map(({ node }) => ( )) return (
{PostsList}
{pageContext.numPages > 1 && }
) } export function Head({ pageContext }: { pageContext: PageContext }) { const meta = getMetadata(pageContext) return } export const archiveQuery = graphql` query ArchiveTemplate($tag: String, $skip: Int, $limit: Int) { allMarkdownRemark( filter: { fields: { type: { nin: "photo" } } frontmatter: { tags: { eq: $tag } } } sort: { fields: { date: DESC } } skip: $skip limit: $limit ) { edges { node { ...PostTeaser } } } } `