@@ -3,6 +3,7 @@ import { Link, graphql } from 'gatsby';
33import Helmet from 'react-helmet' ;
44import moment from 'moment' ;
55import Layout from '../layouts' ;
6+ import PostTags from '../components/post-tags' ;
67
78export default function TagTemplate ( { pageContext, data } ) {
89 const { tag, posts } = pageContext ;
@@ -18,20 +19,36 @@ export default function TagTemplate({ pageContext, data }) {
1819 < title > { `Tag: ${ tag } - ${ siteMetadata . title } ` } </ title >
1920 </ Helmet >
2021
21- < h1 > Posts tagged “{ tag } ”</ h1 >
22-
23- < ul style = { { listStyle : 'none' , padding : 0 } } >
24- { postData . map ( ( { frontmatter, excerpt, fields, html } ) => (
25- < li key = { frontmatter . path } style = { { marginBottom : '2rem' } } >
26- < h2 >
27- < Link to = { frontmatter . path } > { frontmatter . title } </ Link >
28- </ h2 >
29- < p style = { { fontStyle : 'italic' } } >
30- { moment ( frontmatter . date ) . format ( 'MMMM Do YYYY' ) }
31- </ p >
32- < p > { excerpt } </ p >
33- </ li >
34- ) ) }
22+ < h1
23+ style = { {
24+ fontSize : '1.25em' ,
25+ border : '1px dotted #333' ,
26+ padding : '0.5em' ,
27+ marginBottom : '2em' ,
28+ } }
29+ >
30+ Posts tagged “{ tag } ”
31+ </ h1 >
32+
33+ < ul style = { { listStyle : 'none' , padding : 0 , margin : 0 } } >
34+ { postData . map ( ( { frontmatter, excerpt, fields, html, id } ) => {
35+ const formattedDate = moment ( frontmatter . date ) . format ( 'MMMM Do YYYY' ) ;
36+
37+ return (
38+ < li key = { id } style = { { marginBottom : '2em' } } >
39+ < h2 style = { { fontSize : '1.2em' , marginBottom : '1em' } } >
40+ < Link to = { frontmatter . path } > { frontmatter . title } </ Link >
41+ </ h2 >
42+
43+ < p style = { { marginBottom : '1em' } } >
44+ < span style = { { fontStyle : 'italic' } } > { formattedDate } </ span > { ' ' }
45+ — { excerpt }
46+ </ p >
47+
48+ { frontmatter . tags && < PostTags tags = { frontmatter . tags } /> }
49+ </ li >
50+ ) ;
51+ } ) }
3552 </ ul >
3653 </ Layout >
3754 ) ;
@@ -52,6 +69,7 @@ export const pageQuery = graphql`
5269 title
5370 path
5471 date
72+ tags
5573 }
5674 excerpt(pruneLength: 140)
5775 }
0 commit comments