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

56 lines
1.2 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'
import styles from './tags.module.scss'
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[] }
}
}
2020-07-11 10:29:42 +02:00
const TagsPage = ({ data }: TagsPageProps): ReactElement => (
<Page title={page.frontmatter.title} post={page}>
2019-11-08 15:31:43 +01:00
<ul className={styles.tags}>
{data.allMarkdownRemark.group
.sort((a, b) => b.totalCount - a.totalCount)
.map((tag: Tag) => (
<li key={tag.fieldValue}>
<Tag
name={tag.fieldValue}
url={`/tags/${tag.fieldValue}/`}
count={tag.totalCount}
style={{ fontSize: `${100 + tag.totalCount * 2}%` }}
/>
</li>
))}
</ul>
</Page>
)
export default TagsPage
export const tagsPageQuery = graphql`
query {
allMarkdownRemark {
group(field: frontmatter___tags) {
fieldValue
totalCount
}
}
}
`