npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gatsby-source-google-docs

v3.2.2

Published

Gatsby plugin to use Google Docs as a data source

Readme

Npm Build Status Coverage Downloads PRs welcome MIT license Sponsor


gatsby-source-google-docs is a Gatsby plugin to use Google Docs as a data source.

  • 🖋 Best online WYSIWYG editor
  • 🖥 Desktop web app
  • 📱 Mobile app
  • 🛩 Offline redaction
  • 🔥 No need for external CMS
  • ✅ No more content in your source code

Features

  • Documents synced to real Markdown or MDX files, so gatsby-transformer-remark and gatsby-plugin-mdx pick them up
  • Pages created from the Google Drive tree, with your own templates
  • gatsby-plugin-image and gatsby-image support
  • Incremental builds: only the documents and images that changed are fetched
  • Gatsby v5 and Gatsby Cloud support

The sync is done by google-docs-sync and the conversion by google-docs-to-markdown: see them for the Google Docs formatting supported (headings, lists, tables, images, code, footnotes...), the metadata and the shared options.

Documentation

To preview what you can do, please checkout the documentation website.

Two runnable examples live in this repository, both sourcing the folder above:

💯 100% content of the website is from Google Docs. Please suggest edits to improve it.

Installation

Requires Node 22.12 or later and Gatsby 5.3 or later. Gatsby 5 does not support Node 26 yet.

Download gatsby-source-google-docs and gatsby-transformer-remark (or gatsby-plugin-mdx for advanced usage)

npm install gatsby-source-google-docs gatsby-transformer-remark
  • gatsby-source-google-docs transform Google Docs to Markdown, with google-docs-sync, which you can also use without Gatsby
  • gatsby-transformer-remark transform Markdown to HTML
  • gatsby-plugin-mdx transform Markdown to MDX

Token generation

The plugin needs 3 .env variables (GOOGLE_OAUTH_CLIENT_ID, GOOGLE_OAUTH_CLIENT_SECRET and GOOGLE_DOCS_TOKEN). Run the following command at the root of your project to generate them, the google-docs-sync documentation gives the details:

npx gatsby-source-google-docs-token

Usage

Organize your documents

Go to your Google Drive, create a folder and put some documents inside it. The folders tree gives the slugs and breadcrumbs, and the description of the folders and documents holds their YAML metadata (template, locale, slug, date, exclude, skip, ...): see organize your documents.

Every metadata is available under frontmatter in the File nodes of the documents.

Add the plugin to your gatsby-config.js file

The plugin takes the options of google-docs-sync (folder, outputDir, cacheDir, extension, imagesOptions, debug) and the conversion options of google-docs-to-markdown (escapeMdxSyntax, demoteHeadings, keepDefaultStyle and the skip* ones), with the same defaults. These ones are specific to Gatsby:

| Option | Required | Type | Default | Example | | ----------- | -------- | ------- | ------- | ------------ | | createPages | false | Boolean | false | true | | pageContext | false | Array | [] | ["locale"] |

module.exports = {
  plugins: [
    {
      resolve: "gatsby-source-google-docs",
      options: {
        // https://drive.google.com/drive/folders/FOLDER_ID
        folder: "FOLDER_ID",
        createPages: true,
      },
    },
    "gatsby-transformer-remark",
    //
    // OR "gatsby-plugin-mdx" for advanced usage using MDX
    //
    // You need some transformations?
    // Checkout https://www.gatsbyjs.com/plugins/?=gatsby-remark
    // And pick-up some plugins
  ],
}

gatsby-plugin-sharp, gatsby-transformer-sharp and gatsby-remark-images are required if you want to take advantage of gatsby-image blur-up technique.

npm install gatsby-plugin-sharp gatsby-transformer-sharp gatsby-remark-images
module.exports = {
  plugins: [
    "gatsby-source-google-docs",
    "gatsby-plugin-sharp",
    "gatsby-transformer-sharp",
    {
      resolve: "gatsby-transformer-remark",
      options: {
        plugins: ["gatsby-remark-images"],
      },
    },
  ],
}

Write the code blocks as described in google-docs-to-markdown.

To get Syntax highlighting, I recommend using prismjs but it's not mandatory.

npm install gatsby-remark-prismjs prismjs

Add the gatsby-remark-prismjs plugin to your gatsby-config.js

module.exports = {
  plugins: [
    "gatsby-source-google-docs",
    {
      resolve: "gatsby-transformer-remark",
      options: {
        plugins: ["gatsby-remark-prismjs"],
      },
    },
  ],
}

Import a prismjs theme in your gatsby-browser.js

require("prismjs/themes/prism.css")

How documents reach Gatsby

The plugin writes every document to disk as a real markdown file, under outputDir (content/google-docs by default), with its images next to it: see the output of google-docs-sync. File nodes are created for all of them, so gatsby-transformer-remark and gatsby-plugin-mdx pick them up like any other local file.

outputDir is managed by the plugin: files it did not write are deleted on every build, so point it at a directory of its own and add it to your .gitignore.

This is why MDX works again. Since v4, gatsby-plugin-mdx compiles MDX through webpack from a file path and only supports files sourced from the filesystem, so documents kept in memory could never become MDX. Set extension: "mdx" to author your documents as MDX.

⚠️ MDX only supports CommonMark, and this plugin generates GitHub Flavored Markdown: without remark-gfm, tables and ~~strikethrough~~ are rendered as raw text. remark-gfm is ESM only, so the config has to be a gatsby-config.mjs file — see examples/mdx.

⚠️ By default, a document's text is escaped before being written: a stray, unmatched < or { (a <placeholder> convention, a generic <T>, ...) makes MDX v2 fail the whole build, not just that document. A well-formed tag compiles fine either way — <GatsbyLogo /> works whether escaped or not — so this only matters for text that isn't a deliberate component. If every document on your site deliberately embeds live JSX/components as literal text, and you've made sure none of them contain a stray </{ otherwise, set escapeMdxSyntax: false to compile them as intended.

// gatsby-config.mjs
import remarkGfm from "remark-gfm"

const config = {
  plugins: [
    {
      resolve: "gatsby-source-google-docs",
      options: {folder: "FOLDER_ID", extension: "mdx", createPages: true},
    },
    {
      resolve: "gatsby-plugin-mdx",
      options: {
        mdxOptions: {remarkPlugins: [remarkGfm]},
        gatsbyRemarkPlugins: ["gatsby-remark-images"],
      },
    },
  ],
}

export default config

Only what changed is fetched

A build only fetches the documents and images that changed since the previous one. They are kept in the .google-docs directory next to your gatsby-config.js (the cacheDir option), which is not the Gatsby cache, on purpose: Gatsby empties its own whenever a plugin version, package.json, gatsby-config.js or gatsby-node.js changes, and a continuous integration job never has one. Add .google-docs to your .gitignore, or commit it to give your continuous integration a folder it does not have to fetch. See how the cache works.

Read the comments

With the comments option, the comments of a document are available under frontmatter: frontmatter { comments { content quote author { displayName } } }.

Create templates and pages

Using createPages: true option, pages will be created automatically. You need to create templates and define wich template to use using YAML metadata.

You can set page: false metadata for a document to prevent a page creation

Every field of your document metadata is available under frontmatter:

export const pageQuery = graphql`
  query Page($slug: String!) {
    page: markdownRemark(frontmatter: {slug: {eq: $slug}}) {
      html
      frontmatter {
        name
        breadcrumb {
          name
          slug
        }
        cover {
          image {
            childImageSharp {
              gatsbyImageData
            }
          }
        }
      }
    }
  }
`

Checkout the example template and adapt it to your needs.

You can use pageContext option if you need extra data into the context of your pages.

If you prefer to create pages manualy, checkout the createPages API et adapt it to your needs.

Trigger production builds

  • Go to Google Drive example folder
  • Make a copy of Trigger Gatsby Build file using Right Click -> Make a copy
  • Open your copy and update the Build Webhook URL in A2
  • Click the Deploy button to trigger a new build

This method works with any hosting services: Gatsby Cloud, Netlify...

Migrating from v2

v3 writes documents to the filesystem instead of keeping them in memory. That is what makes MDX and the current gatsby-plugin-mdx usable again, but it changes how documents are queried.

The GoogleDocs node type is gone. Documents are now MarkdownRemark (or Mdx) nodes, and everything that used to sit on the node is in frontmatter:

- page: googleDocs(slug: {eq: $slug}) {
-   name
-   cover {
-     image {
-       childImageSharp {
-         gatsbyImageData
-       }
-     }
-   }
-   childMarkdownRemark {
-     html
-   }
- }
+ page: markdownRemark(frontmatter: {slug: {eq: $slug}}) {
+   html
+   frontmatter {
+     name
+     cover {
+       image {
+         childImageSharp {
+           gatsbyImageData
+         }
+       }
+     }
+   }
+ }

Other things to know:

  • allGoogleDocs becomes allMarkdownRemark (or allMdx). These types are shared with any other markdown your site sources, so filter on frontmatter: {slug: {ne: null}} if you need only Google Docs documents.
  • related is now a list of document ids instead of linked nodes.
  • Add outputDir (content/google-docs by default) and cacheDir (.google-docs by default) to your .gitignore.
  • Node 22 or 24 is required, and gatsby@^5 is now a peer dependency.

Showcase

You are using gatsby-source-google-docs for your website? Thank you! Please add the link below:

Support this project