Skip to content

Commit 0c62467

Browse files
Add post images. Change active links to conditionally render based on props
1 parent eeab18d commit 0c62467

File tree

10 files changed

+62
-52
lines changed

10 files changed

+62
-52
lines changed

studio/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@sanity/vision": "^1.149.0",
2525
"prop-types": "^15.6",
2626
"react": "^16.2",
27-
"react-dom": "^16.2"
27+
"react-dom": "^16.2",
28+
"sanity-plugin-asset-source-unsplash": "^0.1.3"
2829
},
2930
"devDependencies": {}
3031
}

studio/sanity.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"@sanity/default-layout",
1414
"@sanity/default-login",
1515
"@sanity/desk-tool",
16-
"@sanity/code-input"
16+
"@sanity/code-input",
17+
"asset-source-unsplash"
1718
],
1819
"env": {
1920
"development": {

studio/schemas/post.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ export default {
4444
// dateFormat: 'YYYY-MM-DD',
4545
// }
4646
},
47-
{
48-
title: 'Image',
49-
name: 'image',
50-
type: 'image'
51-
},
5247
{
5348
title: 'Author',
5449
name: 'author',
@@ -77,6 +72,11 @@ export default {
7772
title: 'Slug',
7873
name: 'slug',
7974
type: 'slug',
75+
},
76+
{
77+
title: 'Image',
78+
name: 'image',
79+
type: 'image'
8080
}
8181
]
8282
}

studio/yarn.lock

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6115,7 +6115,7 @@ promise@^7.1.1:
61156115
dependencies:
61166116
asap "~2.0.3"
61176117

6118-
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
6118+
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@~15.7.2:
61196119
version "15.7.2"
61206120
resolved "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
61216121
dependencies:
@@ -6428,6 +6428,13 @@ react-onclickoutside@^6.7.1:
64286428
version "6.9.0"
64296429
resolved "https://registry.npmjs.org/react-onclickoutside/-/react-onclickoutside-6.9.0.tgz#a54bc317ae8cf6131a5d78acea55a11067f37a1f"
64306430

6431+
react-photo-gallery@^8.0.0:
6432+
version "8.0.0"
6433+
resolved "https://registry.npmjs.org/react-photo-gallery/-/react-photo-gallery-8.0.0.tgz#04ff9f902a2342660e63e6817b4f010488db02b8"
6434+
dependencies:
6435+
prop-types "~15.7.2"
6436+
resize-observer-polyfill "^1.5.0"
6437+
64316438
react-popper@^1.0.2:
64326439
version "1.3.7"
64336440
resolved "https://registry.npmjs.org/react-popper/-/react-popper-1.3.7.tgz#f6a3471362ef1f0d10a4963673789de1baca2324"
@@ -6824,6 +6831,12 @@ same-origin@^0.1.1:
68246831
version "0.1.1"
68256832
resolved "https://registry.npmjs.org/same-origin/-/same-origin-0.1.1.tgz#c2287d3192577df517acbbd6d1451a9c3c3914f5"
68266833

6834+
sanity-plugin-asset-source-unsplash@^0.1.3:
6835+
version "0.1.3"
6836+
resolved "https://registry.npmjs.org/sanity-plugin-asset-source-unsplash/-/sanity-plugin-asset-source-unsplash-0.1.3.tgz#0c66c841322debbe7ef93e66798cbafa1216e392"
6837+
dependencies:
6838+
react-photo-gallery "^8.0.0"
6839+
68276840
sax@~1.2.4:
68286841
version "1.2.4"
68296842
resolved "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

web/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import sanityClient from '@sanity/client'
33
export default sanityClient({
44
projectId: '9k4z7s6m',
55
dataset: 'production',
6-
useCdn: false // `false` if you want to ensure fresh data
6+
useCdn: true // `false` if you want to ensure fresh data
77
})

web/colorsAndThemes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const themes = {
2222
iconAlt: 'Icon of moon for "Dark Mode" theme',
2323
syntax: duotoneDark,
2424
asideBackground: duotoneDark.plain.backgroundColor,
25-
articleLinks: colors.articleLinksDark
25+
articleLinks: colors.articleLinksDark,
26+
listItemBgColor: colors.primaryColor
2627
},
2728
light: {
2829
body: colors.offWhite,
@@ -33,7 +34,8 @@ const themes = {
3334
iconAlt: 'Icon of sun for "Light Mode" theme',
3435
syntax: duotoneLight,
3536
asideBackground: duotoneLight.plain.backgroundColor,
36-
articleLinks: colors.articleLinksLight
37+
articleLinks: colors.articleLinksLight,
38+
listItemBgColor: 'white'
3739
}
3840
}
3941

web/components/GlobalStyles.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ export const GlobalStyles = createGlobalStyle`
5858
}
5959
}
6060
61-
.selectedTag.selectedTag {
62-
background-color: var(--primary-darker)
63-
}
64-
6561
pre {
6662
font-family: 'Courier Prime', monospace;
6763
}

web/components/KeywordTags.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
import styled from 'styled-components'
22
import sortObjProperties from '../utils/sortObjProperties.js'
33

4-
// const TagsContainer = styled.div`
5-
// display: flex;
6-
// justify-content: center;
7-
// flex-wrap: wrap;
8-
// `
94
const TagBtn = styled.button`
105
margin: 15px 0 0 15px;
11-
/* padding: 7px 10px;
12-
color: var(--secondary-color);
13-
font-size: 1em;
14-
border: none;
15-
background-color: var(--primary-color);
16-
font-family: 'Nanum Gothic Coding', monospace;
6+
background-color: ${({ theme }) => theme.listItemBgColor};
7+
color: ${({ theme }) => theme.primaryColor};
178
&:hover {
18-
cursor: pointer;
19-
background-color: var(--primary-darker);
20-
} */
9+
background-color: ${({ theme }) => theme.secondaryColor};
10+
}
11+
${({active, theme }) => active && `
12+
background-color: ${theme.secondaryColor}
13+
`}
2114
`
2215
const TagCount = styled.span`
2316
font-family: 'Fjalla One', sans-serif;
24-
color: var(--secondary-color);
2517
font-size: .8em;
18+
color: ${({ theme }) => theme.primaryColor};
2619
`
2720

2821
function KeywordTags(props) {
@@ -31,15 +24,15 @@ function KeywordTags(props) {
3124

3225
return (
3326
<div>
34-
{/* this prevents `All Posts` button from rendering prior to the rest of the tag buttons */}
27+
{/* this prevents the `All Posts` button from rendering prior to the rest of the tag buttons and allows me to style the background-color independently of the others */}
3528
{tags && (
3629
<TagBtn
3730
onClick={props.handleTagFilter}
3831
id='clearFilter'
39-
className={
32+
active={
4033
props.filteredTags.length > 0
41-
? ''
42-
: 'selectedTag'
34+
? false
35+
: true
4336
}
4437
>
4538
All Posts
@@ -52,10 +45,10 @@ function KeywordTags(props) {
5245
key={tag.name}
5346
id={tag._id}
5447
onClick={props.handleTagFilter}
55-
className={
48+
active={
5649
props.filteredTags.includes(tag._id)
57-
? 'selectedTag'
58-
: ''
50+
? true
51+
: false
5952
}
6053
>
6154
{tag.name}

web/pages/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import KeywordTags from '../components/KeywordTags'
88
import sortObjProperties from '../utils/sortObjProperties.js'
99

1010
const ListItem = styled.li`
11-
margin: 15px 0 0 15px;
11+
margin: 25px 0 0 15px;
1212
padding: 7px 10px;
1313
font-size: 1.75em;
14-
border: 1px solid var(--primary-darker);
14+
background-color: ${({ theme }) => theme.listItemBgColor};
1515
&:hover {
1616
cursor: pointer;
1717
background-color: ${({ theme }) => theme.secondaryColor};
18+
border: ${({ theme }) => theme.secondaryColor};
1819
}
1920
`
2021
const ListItemLink = styled.a`
@@ -185,6 +186,7 @@ export async function getStaticProps() {
185186
const posts = await client.fetch(`
186187
*[ _type == "post" && published ]{
187188
...,
189+
"postImg": image.asset->,
188190
tags[]->{_id, name}
189191
}
190192
`)

web/pages/posts/[slug].js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ const AsideBlock = styled.div`
3232
background-color: ${({ theme }) => theme.asideBackground};
3333
font-size: .9em;
3434
line-height: 1.5em;
35-
/* TODO: dynamically change border and text according to theme? */
36-
/* light text: rgb(178, 151, 98) */
37-
/* light border: */
38-
/* border-left: 1px solid var(--primary-color); */
3935
border: 1px solid rgba(114, 143, 203, .5);
4036
border-left: 2px solid rgba(114, 143, 203, .5);
4137
@@ -47,7 +43,7 @@ const Pre = styled.pre`
4743
text-align: left;
4844
margin: 1em 0;
4945
padding: 0.5em;
50-
/* TODO: is this doing anything? */
46+
/* TODO: is this really doing much? */
5147
& .token-line {
5248
line-height: 1.4em;
5349
height: 1.3em;
@@ -93,11 +89,6 @@ const Button = styled.button`
9389
font-weight: bold;
9490
display: block;
9591
margin: auto;
96-
/* background-color: ${({ theme }) => theme.secondaryColor};
97-
&:hover {
98-
background-color: ${({ theme }) => theme.primaryColor};
99-
color: ${({ theme }) => theme.secondaryColor};
100-
} */
10192
`
10293
const H3 = styled.h3`
10394
font-size: 1.5em;
@@ -106,7 +97,11 @@ const H3 = styled.h3`
10697
font-family: 'Fjalla One', sans-serif;
10798
font-family: 'Cuprum', sans-serif;
10899
`
109-
100+
const PostImg = styled.img`
101+
display: block;
102+
width: 100%;
103+
margin: 1em 0;
104+
`
110105
function Post(props) {
111106
const [articleBtmPos, setArticleBtmPos] = useState(0)
112107
// console.log('propsPost: ', props)
@@ -134,7 +129,7 @@ function Post(props) {
134129
if (!section.children[i].marks) {
135130
// console.log('paragraphBlock inline code')
136131
blockContent.push(
137-
<InlineCodeMain>
132+
<InlineCodeMain key={section.children[i]._key}>
138133
{section.children[i].str_content_inline}
139134
</InlineCodeMain>
140135
)
@@ -292,6 +287,10 @@ function Post(props) {
292287
>
293288
<article>
294289
<h2>{props.title}</h2>
290+
<PostImg
291+
src={props.postImg.url}
292+
alt={`Image of ${props.postImg.description} by ${props.postImg.creditLine}`}
293+
/>
295294
<PostDescription>{props.description}</PostDescription>
296295
{/* // TODO: Add _updatedAt field? */}
297296
<PostDate>
@@ -342,7 +341,10 @@ export async function getStaticPaths() {
342341
export async function getStaticProps(context) {
343342
const { slug } = context.params
344343
const post = await client.fetch(`
345-
*[_type == "post" && slug.current == $slug][0]
344+
*[_type == "post" && slug.current == $slug][0]{
345+
...,
346+
"postImg": image.asset->,
347+
}
346348
`, { slug } )
347349
return { props: post }
348350
}

0 commit comments

Comments
 (0)