@fs/gatsby-plugin-drive
Downloads and caches a Google Drive folder that you can then query with gatsby-source-filesystem.
Last updated 3 months ago by fs .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @fs/gatsby-plugin-drive 
SYNC missed versions from official npm registry.

gatsby-plugin-drive

Downloads and caches a Google Drive folder that you can then query with gatsby-source-filesystem. Optionally exports Google Docs to a usable format.

Installation

yarn add @fs/gatsby-plugin-drive

Usage

In order to use this plugin, you'll need to generate a Google Service Account and share your drive folder with its email. Here's a guide.

// In your gatsby-config.js

plugins: [
  {
    resolve: '@fs/gatsby-plugin-drive',
    options: {
      folderId: 'GOOGLE_DRIVE_FOLDER_ID',
      keyFile: path.resolve(__dirname, 'YOUR_SERVICE_ACCOUNT_KEYFILE.json'),
      destination: path.join(__dirname, 'src/content'),
      exportGDocs: true,
      exportMimeType: 'text/html',
      exportMiddleware: someFunction
    }
  }
]

// Or using environment variables

plugins: [
  {
    resolve: '@fs/gatsby-plugin-drive',
    options: {
      folderId: process.env.GOOGLE_DRIVE_FOLDER_ID,
      key: {
        private_key: process.env.GOOGLE_PRIVATE_KEY,
        client_email: process.env.GOOGLE_CLIENT_EMAIL,
      },
      destination: path.join(__dirname, 'src/content'),
      exportGDocs: true,
      exportMimeType: 'text/html',
      exportMiddleware: someFunction
    }
  }
]

If the exportGDocs option is enabled, all Google Docs in the folder will be exported with the MIME type set in the exportMimeType option. You can see a list of available Google Docs export MIME types here. If the exportGDocs option is disabled, all Google Docs in the folder will be ignored.

The exportMiddleware option is optional. If set, the plugin will run each Google Doc through the function, before it writes it to disk. A usecase for this, could be cleaning up, or manipulating, the HTML that the Google Drive API returns.
The expected function signature is Buffer -> Buffer.

Your drive folder will download all files everytime it builds, except when a file already exists or is cached. To download all files again, set up an npm clean script like:

"clean": "rimraf src/content",

Rate Limiting

The default amount of allowed requests per user per 100 seconds is 1,000. If you're planning to download a large folder with this plugin, you might have to increase this limit. To do that, open the "Services" tab in the Google Cloud Console, select "Google Drive API" and change the limit under "Quotas".

Author

Current Tags

  • 0.2.1                                ...           latest (3 months ago)

5 Versions

  • 0.2.1                                ...           3 months ago
  • 0.2.0                                ...           4 months ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 5
Dependencies (4)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |