Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Step 4: Adding product images to the project with Sanity's Image Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
colbyfayock committed Jan 18, 2021
1 parent 167b089 commit ffa19fc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@sanity/client": "^2.1.4",
"@sanity/image-url": "^0.140.19",
"next": "10.0.5",
"react": "17.0.1",
"react-dom": "17.0.1"
Expand Down
6 changes: 6 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Head from 'next/head'
import imageUrlBuilder from '@sanity/image-url';

import { client } from '../lib/sanity';

import styles from '../styles/Home.module.css'

const builder = imageUrlBuilder(client);

export default function Home({ products }) {
return (
<div className={styles.container}>
Expand All @@ -24,8 +27,11 @@ export default function Home({ products }) {

<div className={styles.grid}>
{products.map(product => {
const { defaultProductVariant = {} } = product;
const { images } = defaultProductVariant;
return (
<a key={product._id} href="#" className={styles.card}>
<img src={builder.image(images[0]).width(300)} />
<h3>{ product.title }</h3>
<p>{ product.blurb.en }</p>
</a>
Expand Down
4 changes: 4 additions & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ a {
* {
box-sizing: border-box;
}

img {
max-width: 100%;
}
41 changes: 41 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@
resolved "https://registry.yarnpkg.com/@rexxars/eventsource-polyfill/-/eventsource-polyfill-1.0.0.tgz#ab46f2f44da23aedd6f51f13d92a194a5367525b"
integrity sha512-YnrybIoM9WFqmeK1D8p/gutqjJnmXCVFWAU3ucka9M7Dzpen3f2Dy4KsC6k1wDHrCtHQuUHHwZovh3i5UPDaZw==

"@sanity/client@^1.149.13":
version "1.150.7"
resolved "https://registry.yarnpkg.com/@sanity/client/-/client-1.150.7.tgz#e05eec38becd5fc8db0ba11d30e406d17013b9de"
integrity sha512-tqIi2MDE8MTJU6N2su0Ct7n+fioYe+tI9ZM2xVrvIUxU1wPxlBEs4f01rRdCttLRp6CoXUmRC7F0j68ZQWMcdA==
dependencies:
"@sanity/eventsource" "1.150.1"
"@sanity/generate-help-url" "1.150.1"
"@sanity/observable" "1.150.1"
deep-assign "^2.0.0"
get-it "^5.0.3"
make-error "^1.3.0"
object-assign "^4.1.1"

"@sanity/client@^2.1.4":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@sanity/client/-/client-2.1.4.tgz#89f64d4ec706b6c9e70605c2249677c22cab984e"
Expand All @@ -172,6 +185,14 @@
make-error "^1.3.0"
object-assign "^4.1.1"

"@sanity/eventsource@1.150.1":
version "1.150.1"
resolved "https://registry.yarnpkg.com/@sanity/eventsource/-/eventsource-1.150.1.tgz#4ccfbbe3936f411c7f15b65674446f46e31cba2a"
integrity sha512-Sqkfr1+X5aJvDYnE6i0ZO5FlFw/wOxLwlSLbWEBWq/l3fvArj2qQp5rH6YNRsg2Dl4hQHOPajUlHbnFPM6SUfA==
dependencies:
"@rexxars/eventsource-polyfill" "^1.0.0"
eventsource "^1.0.6"

"@sanity/eventsource@2.1.4":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@sanity/eventsource/-/eventsource-2.1.4.tgz#d5ee5b3d66279a06e2905fcb36b4524d655d83ad"
Expand All @@ -180,11 +201,31 @@
"@rexxars/eventsource-polyfill" "^1.0.0"
eventsource "^1.0.6"

"@sanity/generate-help-url@1.150.1":
version "1.150.1"
resolved "https://registry.yarnpkg.com/@sanity/generate-help-url/-/generate-help-url-1.150.1.tgz#bc0bda74cd0980e2194d275369e0ebc7970a0a81"
integrity sha512-IK54U7j161Ks6l/4eIg8d9LV4UW968vZr+SsYTa2pzXb3ktDPKcerCx12eDX6HkWGsETZsp0J48QHP3ocVzo9A==

"@sanity/generate-help-url@2.1.4":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@sanity/generate-help-url/-/generate-help-url-2.1.4.tgz#515df06e2e2ea27268afc2fa568a82499dc394d7"
integrity sha512-zMpTeTnd9615/s5DeH54PKU/KShPIkulIeNHRVLeL4EYNGlf2qcfUfbg4LddBEHlvg4ZPMb2MoBFjU8jSqWqQw==

"@sanity/image-url@^0.140.19":
version "0.140.19"
resolved "https://registry.yarnpkg.com/@sanity/image-url/-/image-url-0.140.19.tgz#6adfea7b7768a1708eba6bdcfe9eb0746d2bb1f9"
integrity sha512-itPCTXNyF2MFdXMlwmpcXEiZU7AvSxyQpOaCQ3x8uODIl3GY22KAHYzz6rIGzWU63u0DN/Y8O1ChsblPLqnI5Q==
dependencies:
"@sanity/client" "^1.149.13"

"@sanity/observable@1.150.1":
version "1.150.1"
resolved "https://registry.yarnpkg.com/@sanity/observable/-/observable-1.150.1.tgz#e077a7da3d85a863b80023bcc1a13470dba2ac11"
integrity sha512-GXlXsNOJZ6p4aoMManRQnaL9qy1uXEcS5X1bGZCpKgcX5Rbyku6vYvxNFSGyrRRJRJKLwtUBrLNAjm92jpHFMQ==
dependencies:
object-assign "^4.1.1"
rxjs "^6.5.3"

"@sanity/observable@2.0.9":
version "2.0.9"
resolved "https://registry.yarnpkg.com/@sanity/observable/-/observable-2.0.9.tgz#587d6847b8814a32be1d6c1f2d135df521d09329"
Expand Down

0 comments on commit ffa19fc

Please sign in to comment.