-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
315 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/netlify-cms-media-library-cloudinary/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
<a name="0.2.0"></a> | ||
# 0.2.0 (2018-09-06) | ||
|
||
|
||
### Features | ||
|
||
* **media:** add external media library support, Uploadcare integration ([#1602](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-media-library-uploadcare/issues/1602)) ([0596904](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-media-library-uploadcare/commit/0596904)) | ||
|
||
|
||
|
||
|
||
<a name="0.2.0"></a> | ||
# 0.2.0 (2018-09-06) | ||
|
||
|
||
### Features | ||
|
||
* **media:** add external media library support, Uploadcare integration ([#1602](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-media-library-uploadcare/issues/1602)) ([0596904](https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-media-library-uploadcare/commit/0596904)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Docs coming soon! | ||
|
||
Netlify CMS was recently converted from a single npm package to a "monorepo" of over 20 packages. | ||
That's over 20 Readme's! We haven't created one for this package yet, but we will soon. | ||
|
||
In the meantime, you can: | ||
|
||
1. Check out the [main readme](https://github.com/netlify/netlify-cms/#readme) or the [documentation | ||
site](https://www.netlifycms.org) for more info. | ||
2. Reach out to the [community chat](https://gitter.im/netlify/netlifycms/) if you need help. | ||
3. Help out and [write the readme yourself](https://github.com/netlify/netlify-cms/edit/master/packages/netlify-cms-media-library-cloudinary/README.md)! |
35 changes: 35 additions & 0 deletions
35
packages/netlify-cms-media-library-cloudinary/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "netlify-cms-media-library-cloudinary", | ||
"description": "Cloudinary integration for Netlify CMS", | ||
"version": "0.1.0", | ||
"repository": "https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-media-library-cloudinary", | ||
"bugs": "https://github.com/netlify/netlify-cms/issues", | ||
"main": "dist/netlify-cms-media-library-cloudinary.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"netlify", | ||
"netlify-cms", | ||
"cloudinary", | ||
"image", | ||
"images", | ||
"media", | ||
"assets", | ||
"files", | ||
"uploads" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
"watch": "webpack -w", | ||
"develop": "npm run watch", | ||
"build": "cross-env NODE_ENV=production webpack" | ||
}, | ||
"devDependencies": { | ||
"cross-env": "^5.2.0", | ||
"webpack": "^4.16.1", | ||
"webpack-cli": "^3.1.0" | ||
}, | ||
"peerDependencies": { | ||
"netlify-cms-lib-util": "^2.0.4" | ||
}, | ||
"dependencies": {} | ||
} |
82 changes: 82 additions & 0 deletions
82
packages/netlify-cms-media-library-cloudinary/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { pick } from 'lodash'; | ||
import { loadScript } from 'netlify-cms-lib-util'; | ||
|
||
const defaultOptions = { | ||
use_secure_url: true, | ||
use_transformations: true, | ||
output_filename_only: false, | ||
}; | ||
/** | ||
* This configuration hash cannot be overriden, as the values here are required | ||
* for the integration to work properly. | ||
*/ | ||
const enforcedConfig = { | ||
button_class: undefined, | ||
inline_container: undefined, | ||
insert_transformation: false, | ||
z_index: '99999', | ||
}; | ||
|
||
const defaultConfig = { | ||
multiple: false, | ||
}; | ||
|
||
function getAssetUrl(asset, { use_secure_url, use_transformations, output_filename_only }) { | ||
/** | ||
* Allow output of the file name only, in which case the rest of the url (including) | ||
* transformations) can be handled by the static site generator. | ||
*/ | ||
if (output_filename_only) { | ||
return `${asset.public_id}.${asset.format}`; | ||
} | ||
|
||
/** | ||
* Get url from `derived` property if it exists. This property contains the | ||
* transformed version of image if transformations have been applied. | ||
*/ | ||
const urlObject = asset.derived && use_transformations ? asset.derived[0] : asset; | ||
|
||
/** | ||
* Retrieve the `https` variant of the image url if the `useSecureUrl` option | ||
* is set to `true` (this is the default setting). | ||
*/ | ||
const urlKey = use_secure_url ? 'secure_url' : 'url'; | ||
|
||
return urlObject[urlKey]; | ||
} | ||
|
||
async function init({ options, handleInsert }) { | ||
const { config: providedConfig = {}, ...integrationOptions } = options; | ||
const resolvedOptions = { ...defaultOptions, ...integrationOptions }; | ||
const cloudinaryConfig = { ...defaultConfig, ...providedConfig, ...enforcedConfig }; | ||
const cloudinaryBehaviorConfigKeys = ['default_transformations', 'max_files', 'multiple']; | ||
const cloudinaryBehaviorConfig = pick(cloudinaryConfig, cloudinaryBehaviorConfigKeys); | ||
|
||
await loadScript('https://media-library.cloudinary.com/global/all.js'); | ||
|
||
const insertHandler = data => { | ||
const assets = data.assets.map(asset => getAssetUrl(asset, resolvedOptions)); | ||
handleInsert(cloudinaryConfig.multiple ? assets : assets[0]); | ||
}; | ||
|
||
const mediaLibrary = window.cloudinary.createMediaLibrary(cloudinaryConfig, { insertHandler }); | ||
|
||
return { | ||
show: ({ config: instanceConfig = {}, allowMultiple }) => { | ||
/** | ||
* Ensure multiple selection is not available if the field is configured | ||
* to disallow it. | ||
*/ | ||
if (allowMultiple === false) { | ||
instanceConfig.multiple = false; | ||
} | ||
return mediaLibrary.show({ config: { ...cloudinaryBehaviorConfig, instanceConfig } }); | ||
}, | ||
hide: () => mediaLibrary.hide(), | ||
enableStandalone: () => true, | ||
}; | ||
} | ||
|
||
const cloudinaryMediaLibrary = { name: 'cloudinary', init }; | ||
|
||
export default cloudinaryMediaLibrary; |
3 changes: 3 additions & 0 deletions
3
packages/netlify-cms-media-library-cloudinary/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { getConfig } = require('../../scripts/webpack.js'); | ||
|
||
module.exports = getConfig(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import cms from 'netlify-cms-core/src'; | ||
import uploadcare from 'netlify-cms-media-library-uploadcare/src'; | ||
import cloudinary from 'netlify-cms-media-library-cloudinary/src'; | ||
|
||
const { registerMediaLibrary } = cms; | ||
|
||
registerMediaLibrary(uploadcare); | ||
registerMediaLibrary(cloudinary); |
Oops, something went wrong.