Giter Site home page Giter Site logo

gridsome-source-googlesheet's Introduction

Gridsome Source for Google Sheets

This plugin is based on spenwall/gridsome-source-google-sheets which doesn't seem to be actively maintained.

Source plugin for fetching data from Google Sheets. Supports multiple tabs per sheet and image downloads.

Requirements

Gridsome: >0.7.0

Install

yarn add gridsome-source-googlesheet

npm

npm install gridsome-source-googlesheet

How to use

You will need to generate a google api key here. The sheetId can be found on the sheets url. It is the large hash number near the end. You will also need to make your spreadsheet viewable to the public to use the api credentials.

module.exports = {
  siteName: 'Gridsome',
  plugins: [
    {
      use: 'gridsome-source-google-sheets',
      options: {
        sheetId: 'GOOGLE_SHEET_ID',
        apiKey: 'GOOGLE_API_KEY',
        tab: 'TAB_NAME' // Optional - must match the name of the tab in the Google Sheet.
        type: 'TYPE_NAME', // Optional - default is googleSheet. Used for graphql queries.
        imageFields: ['COLUMN_NAME','COLUMN_NAME'] // Optional - must be an array of column names. Columns must contain direct URLs to image files that are publicly accessible
      }
    },
    {
      use: 'gridsome-source-google-sheets', // To use more than one tab "use" the plugin again
      options: {
        sheetId: 'GOOGLE_SHEET_ID',
        apiKey: 'GOOGLE_API_KEY',
        tab: 'SECOND_TAB_NAME' // Optional - must match the name of the tab in the Google Sheet.
        type: 'SECOND_TYPE_NAME', // Optional - default is googleSheet. Used for graphql queries.
        imageFields: ['COLUMN_NAME','COLUMN_NAME'] // Optional - must be an array of column names. Columns must contain direct URLs to image files that are publicly accessible
      }
    }
  ]
}

Example query on page template

<page-query>
  query MyData {
    allGoogleSheet {
      edges {
        node {
          id
          title
        }
      }
    }
  }
</page-query>

To use data in page

<template>
  <div>
    {{ $page.allGoogleSheet.node.id }}
  </div>
  <div>
    {{ $page.allGoogleSheet.node.title }}
  </div>
</template>

Using Templates

To use this in a template first setup the template route in gridsome.config.js

module.exports = {
  siteName: 'Gridsome',
  plugins: [
    {
      use: 'gridsome-source-google-sheets',
      options: {
        sheetId: 'GOOGLE_SHEET_ID',
        apiKey: 'GOOGLE_API_KEY',
        // type: 'TYPE_NAME', //Optional - default is googleSheet. Used for graphql queries.
      }
    }
  ],
  templates: {
    googleSheet: [
      {
        path: '/:id',
        component: './src/templates/googleSheet.vue'
      }
    ]
  }
}

Example template in src/template/googleSheet.vue

<template>
  <layout>
    <div>{{$page.googleSheet.title}}</div>
    <div>{{$page.googleSheet.body}}</div>
  </layout>
</template>

<page-query>
query Post ($path: String!) {
  googleSheet (path: $path) {
    title
    body
  }
}
</page-query>

gridsome-source-googlesheet's People

Contributors

tscole avatar

Watchers

James Cloos avatar  avatar

gridsome-source-googlesheet's Issues

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.