Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for query param url syntax of IMAGE CDN #566

Merged
merged 12 commits into from
Mar 10, 2023
3 changes: 3 additions & 0 deletions demo-v5/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ module.exports = {
},
},
'gatsby-plugin-netlify',
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
'gatsby-plugin-image-cdn-test',
],
}
3 changes: 2 additions & 1 deletion demo-v5/netlify.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[build]
command = "npm run build"
publish = "public/"
# ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../plugin/"
environment = { GATSBY_CLOUD_IMAGE_CDN = "true" }
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ..; fi;"

[[plugins]]
package = "../plugin/src/index.ts"
Expand Down
1,069 changes: 916 additions & 153 deletions demo-v5/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions demo-v5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"dependencies": {
"@sindresorhus/slugify": "^1.1.2",
"gatsby": "next",
"gatsby-plugin-image": "next",
"gatsby-plugin-sharp": "next",
"gatsby-source-filesystem": "next",
"gatsby-transformer-remark": "next",
"react": "^18.0.0",
Expand Down
25 changes: 25 additions & 0 deletions demo-v5/plugins/gatsby-plugin-image-cdn-test/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
exports.createSchemaCustomization = function createSchemaCustomization({
actions,
}) {
actions.createTypes(`
type UnsplashImage implements Node & RemoteFile {
id: ID!
}
`)
}

exports.sourceNodes = function sourceNodes({ actions }) {
const imageURL = `https://images.unsplash.com/photo-1672823841196-3ec078a2befd`
actions.createNode({
id: 'unsplash-image-1',
internal: {
type: 'UnsplashImage',
contentDigest: `1`,
},
url: imageURL,
filename: imageURL,
mimeType: `image/jpeg`,
width: 1940,
height: 3118,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
68 changes: 68 additions & 0 deletions demo-v5/src/pages/image-cdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as React from 'react'
import { graphql } from 'gatsby'
import { GatsbyImage } from 'gatsby-plugin-image'
import { Layout } from '../layout/default'

const ImageCDNPage = ({ data }) => (
<Layout>
<h1>Image CDN</h1>
<ul>
{data.allUnsplashImage.nodes.map((node) => (
<>
<li key={node.id + '-400'}>
<figure>
<GatsbyImage image={node.gatsbyImage400} alt="400px wide image" />
<figcaption>400px wide image</figcaption>
</figure>
</li>
<li key={node.id + '-200'}>
<figure>
<GatsbyImage image={node.gatsbyImage200} alt="200px wide image" />
<figcaption>200px wide image</figcaption>
</figure>
</li>
<li key={node.id + '-public'}>
<figure>
<img src={node.publicUrl} alt="Public URL" />
<figcaption>Public URL</figcaption>
</figure>
</li>
</>
))}
</ul>
<h2>Old url structure</h2>
<figure>
<img
src="/_gatsby/image/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/dz0zMDAmaD00MDAmZm09YXZpZg==/name.avif"
alt="Gatsby Image"
/>
<figcaption>
/_gatsby/image/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/dz0zMDAmaD00MDAmZm09YXZpZg==.avif
</figcaption>
</figure>
<figure>
<img
src="/_gatsby/file/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/name.avif"
alt="Gatsby File"
/>
<figcaption>
/_gatsby/file/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/name.avif
</figcaption>
</figure>
</Layout>
)

export default ImageCDNPage

export const query = graphql`
{
allUnsplashImage {
nodes {
id
gatsbyImage200: gatsbyImage(width: 200)
gatsbyImage400: gatsbyImage(width: 400)
publicUrl
}
}
}
`
5 changes: 5 additions & 0 deletions demo-v5/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ const links = [
url: 'api/users/123/hello world',
description: 'Captures named path params',
},
{
text: 'IMAGE CDN',
url: 'image-cdn',
description: 'Image CDN demo',
},
]

// markup
Expand Down
3 changes: 3 additions & 0 deletions demo/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ module.exports = {
},
},
'gatsby-plugin-netlify',
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
'gatsby-plugin-image-cdn-test',
],
}
3 changes: 2 additions & 1 deletion demo/netlify.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[build]
command = "npm run build"
publish = "public/"
# ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../plugin/"
environment = { GATSBY_CLOUD_IMAGE_CDN = "true" }
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ..; fi;"

[[plugins]]
package = "../plugin/src/index.ts"
Expand Down
Loading