/
template-tag-page.js
54 lines (50 loc) · 1.12 KB
/
template-tag-page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from "react"
import Link from "gatsby-link"
class TagRoute extends React.Component {
render() {
const posts = this.props.data.allMarkdownRemark.edges
const postLinks = posts.map(post =>
<li key={post.node.fields.slug}>
<Link to={post.node.fields.slug}>
{post.node.frontmatter.title}
</Link>
</li>
)
return (
<div>
<h1>
{this.props.data.allMarkdownRemark.totalCount}
{` `}posts tagged with “{this.props.pathContext.tag}”
</h1>
<ul>
{postLinks}
</ul>
<p>
<Link to="/tags/">Browse all tags</Link>
</p>
</div>
)
}
}
export default TagRoute
export const pageQuery = graphql`
query TagPage($tag: String) {
allMarkdownRemark(
limit: 1000
sort: { fields: [frontmatter___date], order: DESC }
filter: { frontmatter: { tags: { in: [$tag] }, draft: { ne: true } } }
) {
totalCount
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
}
}
`