1
1
import React from 'react' ;
2
+ import { Link } from 'react-router-dom' ;
3
+ import PropTypes from 'prop-types' ;
2
4
3
5
import truncate from 'src/helpers/truncate' ;
4
6
import FlexBox from 'src/Components/FlexBox' ;
5
7
import CardBox from 'src/Components/CardBox' ;
6
8
import { H3 , Span } from 'src/Components/Typo' ;
7
9
import Head from 'src/Components/Head' ;
8
- import Footer from 'src/Components/Footer ' ;
10
+ import Badge from 'src/Components/Badge ' ;
9
11
10
12
// Import all files inside `data` via Webpack require.context
11
13
// Read more:
@@ -18,17 +20,18 @@ const postFiles = postContext
18
20
class Posts extends React . Component {
19
21
state = {
20
22
posts : [ ] ,
23
+ lang : 'en' ,
21
24
}
22
25
23
26
componentDidMount ( ) {
24
27
const posts = postFiles ;
25
-
26
- this . setState ( state => ( { ...state , posts } ) ) ;
28
+ const { lang } = this . props . match . params ;
29
+ this . setState ( state => ( { ...state , posts, lang } ) ) ;
27
30
}
28
31
29
32
render ( ) {
30
33
/* eslint-disable react/no-array-index-key */
31
- const { posts } = this . state ;
34
+ const { posts, lang } = this . state ;
32
35
33
36
return (
34
37
< React . Fragment >
@@ -43,18 +46,31 @@ class Posts extends React.Component {
43
46
>
44
47
{
45
48
posts . map ( ( post , i ) => (
46
- < CardBox key = { i } width = { [ 1 , 1 / 3 ] } px = { [ 1 , 2 , 3 ] } py = { [ 0 , 1 , 2 ] } mx = { [ 1 , 2 , 3 ] } >
47
- < H3 dangerouslySetInnerHTML = { { __html : post . title } } />
49
+ < CardBox width = { [ 1 , 1 / 3 ] } px = { [ 1 , 2 , 3 ] } py = { [ 0 , 1 , 2 ] } mx = { [ 1 , 2 , 3 ] } >
50
+ < Link key = { i } to = { `/${ lang } /posts/${ post . slug } ` } >
51
+ < H3 dangerouslySetInnerHTML = { { __html : post . title } } />
52
+ </ Link >
48
53
< Span dangerouslySetInnerHTML = { { __html : truncate ( post . __content ) } } />
54
+ < FlexBox width = { 1 } >
55
+ < Badge bg = "success" dangerouslySetInnerHTML = { { __html : post . category } } />
56
+ < Span float = "right" dangerouslySetInnerHTML = { { __html : post . date } } />
57
+ </ FlexBox >
49
58
</ CardBox >
50
59
) )
51
60
}
52
61
</ FlexBox >
53
- < Footer />
54
62
</ React . Fragment >
55
63
) ;
56
64
/* eslint-enable react/no-array-index-key */
57
65
}
58
66
}
59
67
68
+ Posts . propTypes = {
69
+ match : PropTypes . shape ( {
70
+ params : PropTypes . shape ( {
71
+ lang : PropTypes . string . isRequired ,
72
+ } ) ,
73
+ } ) . isRequired ,
74
+ } ;
75
+
60
76
export default Posts ;
0 commit comments