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

next-google-docs

v0.2.2

Published

Next.js integration to use Google Docs as a data source

Readme

Npm Build Status Coverage Downloads PRs welcome MIT license Sponsor


next-google-docs is a Next.js integration to use Google Docs as a data source. It syncs a Google Drive folder to Markdown files and images when next dev or next build starts, and gives your App Router pages two functions to read them.

It is an adapter over google-docs-sync, which does the sync, and google-docs-to-markdown, which does the conversion. How the Markdown is rendered is up to you.

Installation

npm install next-google-docs

Next.js 14 or later is required, along with Node 22.12 or later.

Token generation

The sync needs 3 variables, in a .env file that Next.js loads. Run the following command at the root of your project to generate them, the google-docs-sync documentation gives the details:

npx google-docs-sync-token

Add .env to your .gitignore: it holds secrets.

Usage

Wrap your Next.js config:

// next.config.mjs
import {withGoogleDocs} from "next-google-docs"

export default withGoogleDocs(
  {/* your Next.js config */},
  {
    // https://drive.google.com/drive/folders/FOLDER_ID
    folder: "FOLDER_ID",
  }
)

The first argument can be an object or a config function, like the one Next.js accepts. It is returned as it is.

Read the documents from your pages, with the functions of next-google-docs/documents:

// app/[...path]/page.jsx
import {notFound} from "next/navigation"
import {getDocument, getDocuments} from "next-google-docs/documents"

export const dynamicParams = false

export const generateStaticParams = async () =>
  (await getDocuments())
    .filter(({slug}) => slug !== "/")
    .map(({slug}) => ({path: slug.split("/").filter(Boolean)}))

export default async function Page({params}) {
  const document = await getDocument((await params).path)

  if (!document) {
    notFound()
  }

  // Render document.markdown with the tool you prefer
}

Add the synced folders to your .gitignore:

.google-docs
content/google-docs
public/google-docs

Rendering

document.markdown is plain Markdown, without the frontmatter. Use any renderer, for example next-mdx-remote:

import {MDXRemote} from "next-mdx-remote/rsc"
import remarkGfm from "remark-gfm"

;<MDXRemote
  source={document.markdown}
  options={{mdxOptions: {format: "md", remarkPlugins: [remarkGfm]}}}
/>

Set extension: "mdx" to author the documents as MDX.

API

withGoogleDocs(nextConfig, options)

Returns a Next.js config function. It takes the options of google-docs-sync (folder, outputDir, cacheDir, extension, imagesOptions, auth, logger, the converter options), plus:

| Option | Required | Type | Default | Example | | --------- | -------- | ------ | -------------------- | --------------- | | publicDir | false | String | public/google-docs | "public/docs" |

publicDir must be inside public. It is managed by the adapter, which empties it before every sync, so give it a directory of its own. outputDir is managed by google-docs-sync in the same way.

getDocuments(paths?)

Returns the metadata of every synced document: id, name, slug, path, breadcrumb, date, cover, comments (with the comments option), and your own metadata. The image of the cover is a URL.

getDocument(slug, paths?)

Returns {metadata, markdown} for the document of a slug, or null. The slug is a string ("/features/images") or the segments of a catch-all route (["features", "images"]), which is what params.path holds. The images of the Markdown are URLs served from publicDir.

Both functions read the files of outputDir and publicDir set in withGoogleDocs. Pass {outputDir, publicDir} as paths when they run somewhere the config was not loaded.

How it works

  • When the sync runs: once when next dev or next build starts, before any page is rendered. Next.js loads the config again in its workers, the adapter runs the sync only the first time. next start and the other commands do not sync: the documents are read from the build.
  • Caching: the .google-docs folder keeps what was fetched, so the next syncs fetch only the documents that changed on Google Drive. Keep it between CI builds to make them faster.
  • next dev: the documents are synced when the server starts. A change in Google Docs is visible after a restart, there is no live reload of the Drive folder.
  • Images: they are written next to the documents in outputDir, then copied to publicDir, which Next.js serves from the root. The Markdown and the cover point to their URL (/google-docs/images/...). With output: "standalone", copy public as Next.js asks.
  • Turbopack and webpack: the sync runs in the config, which both bundlers load the same way. The page code imports only next-google-docs/documents, so the Google client is not part of your bundle.
  • Static output: with generateStaticParams, every document is prerendered at build time. Pages are rendered from the files, no Google credentials are needed at runtime.

Examples

examples/basic is a minimal App Router site.

Support this project