Skip to content

Commit 8edc6e6

Browse files
committed
Merge the post-list react component into the post list template
1 parent 5b173e9 commit 8edc6e6

File tree

3 files changed

+34
-52
lines changed

3 files changed

+34
-52
lines changed

src/components/PostList/index.jsx

-46
This file was deleted.

src/templates/PostListTemplate/index.jsx

+34-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
import React from 'react'
22
import { graphql } from 'gatsby'
3-
import PostList from '../../components/PostList';
3+
import moment from 'moment'
4+
import Layout from '../../components/Layout'
5+
import PostListHeader from '../../components/PostListHeader'
6+
import PostListItem from '../../components/PostListItem'
7+
import { GlobalLinks } from '../../consts/menuLinks'
8+
import './style.scss'
49

510
class PostListTemplate extends React.Component {
611
render() {
712
const { categoryId, categoryLabel } = this.props.pageContext
13+
const posts = this.props.data.allMarkdownRemark.edges
814

15+
const years = new Set()
16+
let isFirst = true
17+
18+
const items = posts.map(post => {
19+
const year = moment(post.node.frontmatter.date).year()
20+
const showYear = !years.has(year)
21+
years.add(year)
22+
23+
const item = (
24+
<PostListItem
25+
data={post}
26+
key={post.node.fields.slug}
27+
showYear={showYear}
28+
isFirst={isFirst}
29+
/>
30+
)
31+
isFirst = false
32+
33+
return item
34+
})
35+
936
return (
10-
<PostList
11-
categoryId={categoryId}
12-
pageTitle={categoryLabel}
13-
{...this.props}
14-
/>
37+
<Layout subtitle={categoryLabel} globalLinkId={GlobalLinks.Blog.id}>
38+
<div className="posts">
39+
<PostListHeader categoryId={categoryId}/>
40+
{items}
41+
</div>
42+
</Layout>
1543
)
1644
}
1745
}
File renamed without changes.

0 commit comments

Comments
 (0)