11import React from 'react' ;
2+ import { Link } from 'react-router-dom' ;
3+ import PropTypes from 'prop-types' ;
24
35import truncate from 'src/helpers/truncate' ;
46import FlexBox from 'src/Components/FlexBox' ;
57import CardBox from 'src/Components/CardBox' ;
68import { H3 , Span } from 'src/Components/Typo' ;
79import Head from 'src/Components/Head' ;
8- import Footer from 'src/Components/Footer ' ;
10+ import Badge from 'src/Components/Badge ' ;
911
1012// Import all files inside `data` via Webpack require.context
1113// Read more:
@@ -18,17 +20,18 @@ const postFiles = postContext
1820class Posts extends React . Component {
1921 state = {
2022 posts : [ ] ,
23+ lang : 'en' ,
2124 }
2225
2326 componentDidMount ( ) {
2427 const posts = postFiles ;
25-
26- this . setState ( state => ( { ...state , posts } ) ) ;
28+ const { lang } = this . props . match . params ;
29+ this . setState ( state => ( { ...state , posts, lang } ) ) ;
2730 }
2831
2932 render ( ) {
3033 /* eslint-disable react/no-array-index-key */
31- const { posts } = this . state ;
34+ const { posts, lang } = this . state ;
3235
3336 return (
3437 < React . Fragment >
@@ -43,18 +46,31 @@ class Posts extends React.Component {
4346 >
4447 {
4548 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 >
4853 < 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 >
4958 </ CardBox >
5059 ) )
5160 }
5261 </ FlexBox >
53- < Footer />
5462 </ React . Fragment >
5563 ) ;
5664 /* eslint-enable react/no-array-index-key */
5765 }
5866}
5967
68+ Posts . propTypes = {
69+ match : PropTypes . shape ( {
70+ params : PropTypes . shape ( {
71+ lang : PropTypes . string . isRequired ,
72+ } ) ,
73+ } ) . isRequired ,
74+ } ;
75+
6076export default Posts ;
0 commit comments