-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.js
More file actions
164 lines (152 loc) · 3.71 KB
/
preview.js
File metadata and controls
164 lines (152 loc) · 3.71 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { jsx } from '@emotion/core'
/** @jsx jsx */
import styled from '@emotion/styled'
import Layout from '../templates/layout'
import { P, H3, H4, I,
Box, Text, HorizontalRule } from 'bricks'
import PlainLink from '../components/link'
import { css } from 'bricks'
import { Link } from 'gatsby'
import Pagination from '../components/pagination'
import { getCategory, getTags, hypenize } from '../utils'
import { space } from 'styled-system'
import CategoryLink from '../components/categorylink'
const isLast = (arr, index)=> arr.length-1 === index
const getHeading = ({
isFirstPage,
currentPage,
totalPages,
type,
value,
}) => {
if (type === 'category' && value) {
return `Posts in the category “${value}”`;
}
if (['tags','tag'].includes(type) && value) {
return `Posts tagged with “${value}”`;
}
if (type === 'all' && isFirstPage) {
return 'Latest Blog Posts';
}
if (type === 'author' && value) {
return `Posts written by ${value.split('-').join(' ')}`;
}
return `Blog Posts, page ${currentPage} of ${totalPages}`;
};
const ReadPostLink = styled(Link)(
css({
textAlign: 'center',
width: '100%',
borderRadius: '3px',
p: '2px',
display: 'inline-block',
'&:hover':{
bg: 'black.1',
color: 'tint',
},
':visited':{
'&:hover':{
bg: 'black.1',
color: 'tint',
}
}
})
)
const TagLink = styled(PlainLink)`
display: inline-block;
margin-right: 10px;
`
const HeadingLink = styled(Link)(
space,
css({
p: '5px',
borderRadius:'5px',
display: 'inline-block',
textDecoration: 'none',
'&:hover': {
backgroundColor: 'primary',
color: 'secondary',
}
})
)
// refactoring the Link beautifully with invert etc
const Blog = ({frontmatter})=>(
<Box>
<H3>
<HeadingLink ml='-5px' to={frontmatter.link}>
{frontmatter.title }
</HeadingLink>
</H3>
{getCategory(frontmatter) && (
<CategoryLink to={'/category/' + hypenize(getCategory(frontmatter))}>
{getCategory(frontmatter)}
</CategoryLink>
)}
<Box marginTop='2'>
<P>{frontmatter.description}</P>
<Box marginTop='1'>
<Text fontSize={[0,0]} color='black.2'>
{getTags(frontmatter) && getTags(frontmatter).map((tag,i)=> {
const slug = hypenize(tag).toLowerCase()
return (
<TagLink key={tag} to={`/tag/${slug}`}>
<I>#{slug}</I>
</TagLink>
)
})}
</Text>
</Box>
</Box>
<Box marginBottom={3} marginTop={1}>
<ReadPostLink to={frontmatter.link}>Read Post</ReadPostLink>
</Box>
</Box>
)
const JournalPage = ({
pageContext: {
postGroup,
isFirstPage,
isLastPage,
currentPage,
totalPages,
linkBase,
linkRoot,
type,
value,
},
}) => {
let blogs = postGroup
return(
<Layout>
<H4 css={css({color: 'black.1'})}>
{getHeading({
isFirstPage,
currentPage,
totalPages,
type,
value,
})}</H4>
<Box marginTop={6} width={[1, 2/3]}>
{blogs.map((blog,i) => (
<div key={blog.frontmatter.title}>
<Blog frontmatter={blog.frontmatter} />
{ isLast(blogs, i)? '':
<HorizontalRule
width={1}
borderWidth={1}
borderColor={'black.3'}
/>
}
</div>
))}
<Pagination
isFirstPage={isFirstPage}
isLastPage={isLastPage}
currentPage={currentPage}
totalPages={totalPages}
linkBase={linkBase}
/>
</Box>
</Layout>
)}
export default JournalPage;