Code Monkey home page Code Monkey logo

jekyll-gdrive's Introduction

Jekyll Gdrive Plugin

Access data from a Google Drive Spreadsheet in your Jekyll sites

Installation

Add these lines to your Gemfile:

group :jekyll_plugins do
  gem 'jekyll-gdrive'
end

And then execute:

$ bundle install

Usage

Before you can access any data from GDrive you need to configure your GDrive API credentials. After installing the plugin, run:

$ bundle exec jekyll gdrive

And follow the instructions to create an application in Google's developer console and generate a refresh token.

Once you have the token, you need to set it up as an environment variable before running jekyll build. The GDrive plugin will give you an export statement you can use to setup your environment:

$ export GDRIVE=<client_id>:<client_secret>:<your gdrive token>

You'll also need to configure the plugin to use the right spreadsheet.

Add this to your _config.yml:

gdrive:
  sheet: "title of my spreadsheet"

Accessing your Google Sheet data

In any Liquid template you can now use: site.data.google_sheet to access your sheet data.

Example:

<table>
    <thead>
      {% for row in site.data.google_sheet limit:1 %}
        <tr>
          {% for col in row %}<th>{{col}}</th>{% endfor %}
        </tr>
      {% endfor %}
    </thead>
    <tbody>
      {% for row in site.data.google_sheet offset:1 %}
        <tr>
          {% for col in row %}<td>{{col}}</td>{% endfor %}
        </tr>
      {% endfor %}  
    </tbody>
  </table>

Caching

Google's Drive API is not incredibly fast. When working in jekyll serve --watch mode you'll quickly get tired of waiting for the spreadsheet data to load on every refresh.

To work around this you can specify a cache period for the gdrive plugin in the Jekyll configuration:

gdrive:
   sheet: "My sheet"
   cache_period: 5 minutes

This will store the sheet in a local _gdrive_cache file and only reload the sheet data once every 5 minutes.

You can specify the time in seconds, minutes or hours.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/jekyll-gdrive/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

jekyll-gdrive's People

Contributors

biilmann avatar imorente avatar

Watchers

Cantlin Ashrowan avatar James Cloos avatar jpd avatar

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.