1
0
Fork 0
blog/src/pages/tags.tsx

60 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-05-22 14:38:19 +02:00
import React, { ReactElement } from 'react'
2020-07-11 10:29:42 +02:00
import { graphql, PageProps } from 'gatsby'
2020-03-04 22:21:12 +01:00
import Page from '../components/templates/Page'
2019-11-08 15:31:43 +01:00
import Tag from '../components/atoms/Tag'
2021-03-14 02:58:37 +01:00
import { tags } from './tags.module.css'
2019-11-08 15:31:43 +01:00
const page = {
frontmatter: {
title: 'Tags',
description: 'All the tags being used.'
}
}
interface Tag {
fieldValue: string
totalCount: number
}
2020-07-11 10:29:42 +02:00
interface TagsPageProps extends PageProps {
2019-11-08 15:31:43 +01:00
data: {
allMarkdownRemark: { group: Tag[] }
}
}
2021-03-01 00:36:51 +01:00
const TagsPage = (props: TagsPageProps): ReactElement => (
<Page
title={page.frontmatter.title}
post={page}
pathname={props.location.pathname}
>
2021-03-14 02:58:37 +01:00
<ul className={tags}>
2021-03-01 00:36:51 +01:00
{props.data.allMarkdownRemark.group
2019-11-08 15:31:43 +01:00
.sort((a, b) => b.totalCount - a.totalCount)
.map((tag: Tag) => (
<li key={tag.fieldValue}>
<Tag
name={tag.fieldValue}
2020-07-11 11:42:37 +02:00
url={`/archive/${tag.fieldValue}/`}
2019-11-08 15:31:43 +01:00
count={tag.totalCount}
style={{ fontSize: `${100 + tag.totalCount * 2}%` }}
/>
</li>
))}
</ul>
</Page>
)
export default TagsPage
export const tagsPageQuery = graphql`
{
2019-11-08 15:31:43 +01:00
allMarkdownRemark {
group(field: { frontmatter: { tags: SELECT } }) {
2019-11-08 15:31:43 +01:00
fieldValue
totalCount
}
}
}
`