You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-32Lines changed: 71 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
# Gatsby-Source-Cloudinary
2
2
3
-
This source plugin queries media files from a Cloudinary account into `cloudinaryMedia` nodes in your Gatsby project.
3
+
This source plugin queries media files from a Cloudinary account into `CloudinaryMedia` nodes in your Gatsby project.
4
4
5
5
[See a live demo here](https://gsc-sample.netlify.com/)
6
6
7
7
[Here's a tutorial on plugin usage](https://scotch.io/tutorials/handling-images-in-gatsby-with-high-performance)
8
8
9
+
If support for the [gatsby-plugin-image](https://www.gatsbyjs.com/plugins/gatsby-plugin-image/) is needed add and configure the [gatsby-transformer-cloudinary](https://www.gatsbyjs.com/plugins/gatsby-transformer-cloudinary/) plugin.
10
+
9
11
## Motivation
10
12
11
-
Gatsby offers the ability to develop highperformance web pages with a rich developer experience and declarative data fetching Layer with GraphQL.
12
-
Cloudinary provides a robust solution to manage media assets, from storage, optimized delivery, to media transformations. Extending the powers of Gatsby with the use of gatsby-source-cloudinary affords the best of both worlds, to allow users store media assets on Cloudinary,
13
+
Gatsby offers the ability to develop high-performance web pages with a rich developer experience and declarative data fetching Layer with GraphQL.
14
+
Cloudinary provides a robust solution to manage media assets, from storage, and optimized delivery, to media transformations. Extending the powers of Gatsby with the use of gatsby-source-cloudinary affords the best of both worlds, to allow users to store media assets on Cloudinary,
13
15
leveraging Cloudinary's powerful optimization and transformation capabilities in fast sites built with Gatsby.
14
16
15
17
While Cloudinary images with on-the-fly transformations can be used during runtime in Gatsby, gatsby-source-cloudinary utilizes the build optimizations of Gatsby.
@@ -20,55 +22,82 @@ While Cloudinary images with on-the-fly transformations can be used during runti
20
22
- Average of over 60% image optimizations using `f_auto` and `q_auto` applied by default.
21
23
- Query Cloudinary images in Gatsby's data layer using GraphQL.
22
24
- Utilize Cloudinary's robust transformation suite in media files on a Gatsby site.
23
-
- Manage media assets of an application completely on Cloudinary rather than directly in the codebase.
25
+
- Manage media assets of an application entirely on Cloudinary rather than directly in the codebase.
24
26
25
-
Looking to use the features of Gatsby-Image with Cloudinary optimized storage, transformations and delivery? Checkout the [gatsby-transformer-cloudinary](https://www.npmjs.com/package/gatsby-transformer-cloudinary) plugin.
27
+
Looking to use the features of Gatsby-Image with Cloudinary optimized storage, transformations, and delivery? Check out the [gatsby-transformer-cloudinary](https://www.npmjs.com/package/gatsby-transformer-cloudinary) plugin.
26
28
27
29
## Example usage
28
30
29
-
Here's a sample usage of the source plugin to create an image gallery from images stored on Cloudinary:
31
+
Example showing use with and without [gatsby-plugin-image](https://www.gatsbyjs.com/plugins/gatsby-plugin-image/) + [[gatsby-transformer-cloudinary](https://www.gatsbyjs.com/plugins/gatsby-transformer-cloudinary/). The latter will add the `gatsbyImageData` resolver used below.
<img width="300" src={imageSrc} alt={'no alt :('} />
59
+
</>
51
60
);
52
61
};
62
+
63
+
exportdefaultSingleImage;
53
64
```
54
65
55
66
## Installation
56
67
57
-
Install the source plugin using either `npm` or `yarm`:
68
+
Install the source plugin using either `npm` or `yarn`:
58
69
59
70
```bash
60
71
npm install --save gatsby-source-cloudinary
61
72
```
62
73
74
+
```bash
75
+
yarn add --save gatsby-source-cloudinary
76
+
```
77
+
78
+
### Gatsby Plugin Image
79
+
80
+
To use with [gatsby-plugin-image](https://www.gatsbyjs.com/plugins/gatsby-plugin-image/) you'll need to install it along with [gatsby-transformer-cloudinary](https://www.gatsbyjs.com/plugins/gatsby-transformer-cloudinary/).
81
+
82
+
> **NOTE:** Currently in beta, may be used with both Gatsby v3 and Gatsby v4
Cloudinary offers a generous free tier which is more than enough to bootstrap projects.
66
-
Obtain your cloudname, key and secret from your cloudinary console when you signup at [Cloudinary.com](https://cloudinary.com).
95
+
Obtain your cloudname, key, and secret from your cloudinary console when you signup at [Cloudinary.com](https://cloudinary.com).
67
96
68
97
### Environment configuration
69
98
70
99
Store your `cloudName`, `apiKey` and `apiSecret` as environment variables for security.
71
-
To do this, create a file in the root of the project named `.env`. Add your environment variables in it with:
100
+
To do this, create a file in the project's root named `.env`. Add your environment variables in it with:
72
101
73
102
```
74
103
CLOUDINARY_API_KEY=INSERT API KEY HERE
@@ -88,7 +117,7 @@ In your `gatsby-config.js` file, require and configure `dotenv` with:
88
117
require('dotenv').config();
89
118
```
90
119
91
-
There are several options to configuring`dotenv` to use different env files either in development or production. You can find that [here](https://www.npmjs.com/package/dotenv).
120
+
There are several options to configure`dotenv` to use different env files either in development or production. You can find that [here](https://www.npmjs.com/package/dotenv).
92
121
93
122
Add the `.env` file to `.gitignore` so it's not committed.
94
123
@@ -99,17 +128,27 @@ Ensure to configure the environment variables on deployment as well.
99
128
In your `gatsby-config.js` file, include the plugin like this:
100
129
101
130
```js
102
-
{
103
-
resolve:`gatsby-source-cloudinary`,
104
-
options: {
105
-
cloudName:process.env.CLOUDINARY_CLOUD_NAME,
106
-
apiKey:process.env.CLOUDINARY_API_KEY,
107
-
apiSecret:process.env.CLOUDINARY_API_SECRET,
108
-
resourceType:`image`,
109
-
type:`type Value`,
110
-
prefix:`abc-xyz/`
111
-
}
112
-
}
131
+
module.exports= {
132
+
plugins: [
133
+
{
134
+
resolve:`gatsby-source-cloudinary`,
135
+
options: {
136
+
cloudName:process.env.CLOUDINARY_CLOUD_NAME,
137
+
apiKey:process.env.CLOUDINARY_API_KEY,
138
+
apiSecret:process.env.CLOUDINARY_API_SECRET,
139
+
resourceType:`image`,
140
+
maxResults:22,
141
+
},
142
+
},
143
+
{
144
+
resolve:`gatsby-transformer-cloudinary`,
145
+
options: {
146
+
transformTypes: [`CloudinaryMedia`],
147
+
},
148
+
},
149
+
`gatsby-plugin-image`,
150
+
],
151
+
};
113
152
```
114
153
115
154
### Plugin options
@@ -121,7 +160,7 @@ You can find the plugin options in the table below.
121
160
|`cloudName`| string | true | n/a | Cloud name of your Cloudinary account, can be obtained from your [Cloudinary console](https://cloudinary.com/console/). This should be stored and retrieved as an environment variable. |
122
161
|`apiKey`| string | true | na/a | API Key of your Cloudinary account, can be obtained from your [Cloudinary console](https://cloudinary.com/console/). This should be stored and retrieved as an environment variable. |
123
162
|`apiSecret`| string | true | n/a | API Secret of your Cloudinary account, can be obtained from your [Cloudinary console](https://cloudinary.com/console/). This should be stored and retrieved as an environment variable. |
124
-
|`resourceType`| string | false | image | This is the type of file. Possible values: image, raw, video. Note: Use the video resource type for all video resources as well as for audio files, such as .mp3. |
163
+
|`resourceType`| string | false | image | This is the file type. Possible values: image, raw, video. Note: Use the video resource type for all video resources as well as for audio files, such as .mp3.|
125
164
|`type`| string | false | all | This is the storage type: upload, private, authenticated, facebook, twitter, gplus, instagram_name, gravatar, youtube, hulu, vimeo, animoto, worldstarhiphop or dailymotion. |
126
165
|`maxResults`| integer | false | 10 | Max number of resources to return |
127
166
|`tags`| boolean | false | false | If true, include the list of tag names assigned to each resource |
@@ -134,7 +173,7 @@ An example `prefix` value is `gatsby-anime-videos/`. This will fetch only media
134
173
135
174
The `f_auto` and `q_auto` Cloudinary transformations are applied automatically to all media queries. This optimizes the delivered media quality and format.
136
175
137
-
> All media files sourced from Cloudinary are done when Gatsby creates an optimized build, hence you will need to trigger a new production build whenever new media files are added directly on Cloudinary.
176
+
> All media files sourced from Cloudinary are done when Gatsby creates an optimized build; hence you will need to trigger a new production build whenever new media files are added directly on Cloudinary.
138
177
139
178
## How to use
140
179
@@ -181,7 +220,7 @@ const Images = () => {
181
220
182
221
## Contribute
183
222
184
-
Want to contribute to make this tool even better? Feel free to send in issues and pull requests on feature requests, fixes, bugs, typos, performance lapses or any other challenge faced with using this tool.
223
+
Want to contribute to making this tool even better? Feel free to send in issues and pull requests on feature requests, fixes, bugs, typos, performance lapses, or any other challenge faced with using this tool.
0 commit comments