Skip to content

Commit 5874f67

Browse files
piehkodiakhq[bot]
andauthored
feat: add support for query param url syntax of IMAGE CDN (#566)
* chore: add IMAGE_CDN setup to demo-v5 site * feat: support query params style IMAGE CDN url syntax * build deploy preview when there are changes in plugin or in demo site * chore: resolve some linting errors * chore: refactor handling of multiple url structures * fix: preserve 'filename' on redirect * chore: update ignore in netlify.toml for demo sites * chore: update demo-v5 image cdn page * chore: update ignore commands * chore: add IMAGE_CDN setup to demo site * chore: add image-cdn link to demo index --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent d86845c commit 5874f67

File tree

18 files changed

+1508
-174
lines changed

18 files changed

+1508
-174
lines changed

demo-v5/gatsby-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ module.exports = {
1818
},
1919
},
2020
'gatsby-plugin-netlify',
21+
`gatsby-plugin-image`,
22+
`gatsby-plugin-sharp`,
23+
'gatsby-plugin-image-cdn-test',
2124
],
2225
}

demo-v5/netlify.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[build]
22
command = "npm run build"
33
publish = "public/"
4-
# ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../plugin/"
4+
environment = { GATSBY_CLOUD_IMAGE_CDN = "true" }
5+
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ..; fi;"
56

67
[[plugins]]
78
package = "../plugin/src/index.ts"

demo-v5/package-lock.json

Lines changed: 916 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo-v5/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"dependencies": {
2323
"@sindresorhus/slugify": "^1.1.2",
2424
"gatsby": "next",
25+
"gatsby-plugin-image": "next",
26+
"gatsby-plugin-sharp": "next",
2527
"gatsby-source-filesystem": "next",
2628
"gatsby-transformer-remark": "next",
2729
"react": "^18.0.0",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
exports.createSchemaCustomization = function createSchemaCustomization({
2+
actions,
3+
}) {
4+
actions.createTypes(`
5+
type UnsplashImage implements Node & RemoteFile {
6+
id: ID!
7+
}
8+
`)
9+
}
10+
11+
exports.sourceNodes = function sourceNodes({ actions }) {
12+
const imageURL = `https://images.unsplash.com/photo-1672823841196-3ec078a2befd`
13+
actions.createNode({
14+
id: 'unsplash-image-1',
15+
internal: {
16+
type: 'UnsplashImage',
17+
contentDigest: `1`,
18+
},
19+
url: imageURL,
20+
filename: imageURL,
21+
mimeType: `image/jpeg`,
22+
width: 1940,
23+
height: 3118,
24+
})
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

demo-v5/src/pages/image-cdn.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import * as React from 'react'
2+
import { graphql } from 'gatsby'
3+
import { GatsbyImage } from 'gatsby-plugin-image'
4+
import { Layout } from '../layout/default'
5+
6+
const ImageCDNPage = ({ data }) => (
7+
<Layout>
8+
<h1>Image CDN</h1>
9+
<ul>
10+
{data.allUnsplashImage.nodes.map((node) => (
11+
<>
12+
<li key={node.id + '-400'}>
13+
<figure>
14+
<GatsbyImage image={node.gatsbyImage400} alt="400px wide image" />
15+
<figcaption>400px wide image</figcaption>
16+
</figure>
17+
</li>
18+
<li key={node.id + '-200'}>
19+
<figure>
20+
<GatsbyImage image={node.gatsbyImage200} alt="200px wide image" />
21+
<figcaption>200px wide image</figcaption>
22+
</figure>
23+
</li>
24+
<li key={node.id + '-public'}>
25+
<figure>
26+
<img src={node.publicUrl} alt="Public URL" />
27+
<figcaption>Public URL</figcaption>
28+
</figure>
29+
</li>
30+
</>
31+
))}
32+
</ul>
33+
<h2>Old url structure</h2>
34+
<figure>
35+
<img
36+
src="/_gatsby/image/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/dz0zMDAmaD00MDAmZm09YXZpZg==/name.avif"
37+
alt="Gatsby Image"
38+
/>
39+
<figcaption>
40+
/_gatsby/image/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/dz0zMDAmaD00MDAmZm09YXZpZg==.avif
41+
</figcaption>
42+
</figure>
43+
<figure>
44+
<img
45+
src="/_gatsby/file/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/name.avif"
46+
alt="Gatsby File"
47+
/>
48+
<figcaption>
49+
/_gatsby/file/aHR0cHM6Ly9pbWFnZXMudW5zcGxhc2guY29tL3Bob3RvLTE1MTc4NDk4NDU1MzctNGQyNTc5MDI0NTRhP2l4bGliPXJiLTEuMi4xJml4aWQ9TW53eE1qQTNmREI4TUh4d2FHOTBieTF3WVdkbGZIeDhmR1Z1ZkRCOGZIeDgmYXV0bz1mb3JtYXQmZml0PWNyb3Amdz0yMDAwJnE9ODA=/name.avif
50+
</figcaption>
51+
</figure>
52+
</Layout>
53+
)
54+
55+
export default ImageCDNPage
56+
57+
export const query = graphql`
58+
{
59+
allUnsplashImage {
60+
nodes {
61+
id
62+
gatsbyImage200: gatsbyImage(width: 200)
63+
gatsbyImage400: gatsbyImage(width: 400)
64+
publicUrl
65+
}
66+
}
67+
}
68+
`

demo-v5/src/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ const links = [
113113
url: 'api/users/123/hello world',
114114
description: 'Captures named path params',
115115
},
116+
{
117+
text: 'IMAGE CDN',
118+
url: 'image-cdn',
119+
description: 'Image CDN demo',
120+
},
116121
]
117122

118123
// markup

demo/gatsby-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ module.exports = {
1717
},
1818
},
1919
'gatsby-plugin-netlify',
20+
`gatsby-plugin-image`,
21+
`gatsby-plugin-sharp`,
22+
'gatsby-plugin-image-cdn-test',
2023
],
2124
}

demo/netlify.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[build]
22
command = "npm run build"
33
publish = "public/"
4-
# ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../plugin/"
4+
environment = { GATSBY_CLOUD_IMAGE_CDN = "true" }
5+
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ..; fi;"
56

67
[[plugins]]
78
package = "../plugin/src/index.ts"

0 commit comments

Comments
 (0)