Git Product home page Git Product logo

bridgetown-cloudinary's Introduction

Bridgetown Cloudinary Plugin

Bridgetown is a Ruby-powered static site generator. Cloudinary is digital asset management service which makes uploading and serving resized, transformed, and compressed images and videos easy and fast.

This plugin wires the two up so you can use Cloudinary images in your blog posts, articles, product pages, site templates, and anywhere else you might need to reference media optimized for mobile and responsive design.

Note
For users who may be familiar with the jekyll-cloudinary plugin, this is unrelated and the usage is quite different. This plugin assumes you store your images in Cloudinary directly, not your repo.

Installation

You can install this plugin via an automation to guide you through the configuration:

bin/bridgetown apply https://github.com/bridgetownrb/bridgetown-cloudinary

Otheriwse, you can run this command to add this plugin to your site's Gemfile:

$ bundle add bridgetown-cloudinary

Then add the initializer to your configuration in config/initializers.rb and point to your Cloudinary cloud name:

init :"bridgetown-cloudinary" do
  cloud_name "my-cloud-name"
end

Note
For Bridgetown 1.1 or earlier, read these instructions.

Usage

The simplest usage of the Bridgetown Cloudinary plugin is to add a cloudinary_id to the front matter of a resource. For example:

---
title: I'm a Blog Post
cloudinary_id: some-folder-with/image-in-cloudinary
category: neat
---

I'm a blog post with an image!

The plugin will automatically add image.path front matter with a generated URL to the image in Cloudinary using the default configured transformation open_graph. This sizes and compresses an image suitable for use on Twitter, Facebook, etc. (See below for information on how to change the default transformation or add your own.)

You can use image.path in a template:

{{ post.image.path }}

Since image.path is also referenced by the Bridgetown Feed and SEO plugins, your Cloudinary images will be picked up in those contexts automatically.

To reference other available sizes, you can use either a Liquid tag or filter, or Ruby helper, depending on your needs. Using a tag:

{% cloudinary_img "Alt text goes here", post.cloudinary_id, "large" %}

Or a filter:

<img alt="Alt text"
     src="{{ post.cloudinary_id | cloudinary_url: "medium" }}"
     />

Or helpers in ERB and other Ruby templates:

<%= cloudinary_img "Alt text goes here", post.data.cloudinary_id %>
<img alt="Alt text"
     src="<%= cloudinary_url post.data.cloudinary_id, :medium %>"
     />

Default Sizes Included

Here's a list of all the Cloudinary transformation strings that ship with the plugin:

open_graph: "c_fill,g_face:center,w_1600,h_900,q_50" # default
tiny: "w_300,c_limit,q_90"
small: "w_600,c_limit,q_85"
medium: "w_1200,c_limit,q_80"
large: "w_1800,c_limit,q_80"
xlarge: "w_2048,c_limit,q_75"

The image format used in all cases is JPG.

Optional Configuration Options

If you'd like to reference any of the configured image sizes directly through front matter as an alternative to using tags or filters, you can switch this on in your bridgetown.config.yml:

cloudinary:
  add_transformed_urls_to_image_front_matter: true

Then you'll be able to reference image sizes like so:

<img alt="Alt text"
     src="{{ post.image.tiny }}"
     />

Be aware that if an image front matter variable has already defined for a document, it will remain intact and the Cloudinary image transformations won't be apply for that document.

You can also change or add your own transformations! Simply define them in your config:

cloudinary:
  transformations:
    tiny: w_300,c_limit,q_90 # this overrides the builtin tiny transformation
    max_bw: e_grayscale,w_4096,c_limit,q_65 # this is a new custom transformation

If you configure transformations to get added to front matter, all custom transformations will show up there as well:

B&W image URL: {{ post.image.max_bw }}

Testing

  • Run bundle exec rspec to run the test suite
  • Or run script/cibuild to validate with Rubocop and test with rspec together

Contributing

  1. Fork it (https://github.com/bridgetownrb/bridgetown-cloudinary/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Releasing

To release a new version of the plugin, simply bump up the version number in version.rb and then run script/release.

bridgetown-cloudinary's People

Contributors

jaredcwhite avatar richnsd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bridgetown-cloudinary's Issues

v2.1 Automation Whitespace Bug

It appears that it doesn't actually break anything so this is low prio. ๐Ÿ˜„

Bug

When running the automation:

bin/bridgetown apply https://github.com/bridgetownrb/bridgetown-cloudinary

On a new Bridgetown v1.2.0.beta3 site, the following output is produced:

  init :"bridgetown-cloudinary"do
    cloud_name "andrewmcodes"
  end

instead of:

  init :"bridgetown-cloudinary" do
    cloud_name "andrewmcodes"
  end

Notice there is no space between the "" and do in the first example.

Reproduction Steps

  1. Run bin/bridgetown apply https://github.com/bridgetownrb/bridgetown-cloudinary in the root of your Bridgetown site
  2. Look at output in config/initializers.rb

Desired Solution

Ideally there would be a space between the end of the " and do here. I tried messing with it for a few minutes and couldn't get it so wanted to get an issue opened for visibility.

Versions

  • Bridgetown 1.2.0.beta3
  • bridgetown-cloudinary 2.1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.