Skip to content

Commit 8b06214

Browse files
Use height/width from Unsplash metadata for post images
1 parent 69d8c58 commit 8b06214

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

web/components/PostImg.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ const PostImg = styled.img`
1212
transition: opacity 400ms ease 0ms;
1313
/* width: 100%; */
1414
/* TODO: what exactly were these supposed to be doing? */
15-
/* top: 0;
16-
left: 0;
17-
display: block; */
15+
/* top: 0; */
16+
/* left: 0; */
17+
/* display: block; */
1818
`
1919
const PostLqipImg = styled(PostImg)`
2020
position: absolute;
21-
/* width: 100%; */
21+
width: 100%;
2222
/* TODO: what exactly were these supposed to be doing? */
2323
/* transform: scale(1);
2424
transition: visibility 0ms ease 400ms; */
@@ -27,43 +27,37 @@ const PhotoCredit = styled.p`
2727
text-align: center;
2828
`
2929

30-
function PostImage(props) {
31-
console.log('Image props: ', props)
30+
function PostImage({ postImg }) {
31+
// console.log('postImg: ', postImg)
3232
const [isLoaded, setIsLoaded] = useState(false);
33-
// const [fullImgUrl, setFullImgUrl] = useState(null)
34-
// const [lqipImgUrl, setLqipImgUrl] = useState(null)
35-
// console.log('isLoaded: ', isLoaded)
36-
37-
// useEffect(() => {
38-
// console.log('useEffect')
39-
// }, [])
40-
41-
// function handleOnLoad() {
42-
// console.log('handleOnLoad: ', isLoaded)
43-
// }
44-
33+
const { width, height } = postImg.metadata.dimensions
34+
// console.log('with/height: ', width + "/" + height)
4535
return (
4636
<PostImgContainer>
4737
<PostLqipImg
48-
src={props.postImg.metadata.lqip}
49-
alt={`Image of ${props.postImg.description} by ${props.postImg.creditLine}`}
38+
src={postImg.metadata.lqip}
39+
alt={`Image of ${postImg.description} by ${postImg.creditLine}`}
5040
style={{ visibility: isLoaded ? "hidden" : "visible" }}
41+
width={width}
42+
height={height}
5143
/>
5244

5345
<PostImg
5446
// key set to unique value ensures that LQIP image doesn't persist on page refresh
5547
key={Date.now()}
5648
onLoad={() => setIsLoaded(true)}
57-
src={props.postImg.url}
58-
alt={`Image of ${props.postImg.description} by ${props.postImg.creditLine}`}
49+
src={postImg.url}
50+
alt={`Image of ${postImg.description} by ${postImg.creditLine}`}
5951
// TODO: move these style tags to Styled Components?
6052
style={{ opacity: isLoaded ? 1 : 0 }}
53+
width={width}
54+
height={height}
6155
/>
6256

6357
<PhotoCredit>
6458
Photo by 
65-
<a href={props.postImg.source.url} target="_blank">
66-
{props.postImg.creditLine.replace('by Unsplash', ' ')}
59+
<a href={postImg.source.url} target="_blank">
60+
{postImg.creditLine.replace('by Unsplash', ' ')}
6761
</a>
6862
on <a href="https://unsplash.com/" target="_blank">Unsplash</a>
6963
</PhotoCredit>

web/pages/posts/[slug].js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ const CodeNote = styled.p`
8585
const ExternalLink = styled.a`
8686
text-decoration: underline;
8787
color: ${({ theme }) => theme.articleLinks};
88-
/* display:inline-block; */
89-
word-break: break-word;
88+
word-break: break-all;
9089
`
9190
const Button = styled.button`
9291
font-size: .8em;

0 commit comments

Comments
 (0)