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 🙏

© 2024 – Pkg Stats / Ryan Hefner

generate-content-spreadsheet

v1.0.16

Published

Use Google Spreadsheet as simple, painless, robust CMS for text and structured content

Downloads

10

Readme

Generate content spreadsheet

Use Google Spreadsheet as simple, painless, robust CMS for text and structured content!

From your (publicly shared) Google Spreadsheet, creates content as JavaScript (TypeScript) object and allows it to be automatically updated whenever you recompile your code and update the spreadsheet.

Works beautifully with NextJS or any Webpack environment where you can add Webpack plugin!

Creates typed content structure so your DevEx is great, as you can just discover the content object as you type.

Based on public-google-sheets-parser JavaScript package, which can parse publically available spreadsheets without the need of authorization.

Example usage (NextJS)

Add to your ./next.config.js:

const { GenerateContentSpreadsheetPlugin } = require("generate-content-spreadsheet");

const nextConfig = {
  reactStrictMode: false,
  webpack: (config, { isServer }) => {
    config.plugins?.push(
      new GenerateContentSpreadsheetPlugin(
        // Script it will write (can be either .js or .ts)
        __dirname + "/components/Content.ts",
        // Variable in source file
        "Strings",
        // Spreadsheet id, see https://www.npmjs.com/package/public-google-sheets-parser
        "MY_SPREADSHEET_ID",
        // Spreadsheet tab name
        "Sheet1",
        // Spreadsheet tab gid
        undefined
      )
    );
    return config;
  },
};

Then, in your code, you can use it like this:

import { Strings } from "../components/Content";

const MyComponent = () => {
  return <div>{Strings.title}</div>;
};

How it works

It uses public-google-sheets-parser to parse your spreadsheet and then writes it to a TypeScript file.

It expects spreadsheet to have following REQUIRED columns:

  • key - JQ path to the object where to put the value, for example "title" or "content.title" or event "content.description[]"
  • value - String value to put in the object. WARNING: Only string values are supported!

Spreadsheet format:

It expects Google Spreadsheet with the following columns:

| key | value | | ------------------ | --------------------------- | | title | My title | | root.title | My index page title | | root.description[] | My index page description 1 | | root.description[] | My index page description 2 |

Resulting output:

export const Strings = {
  title: "My title",
  root: {
    title: "My index page title",
    description: ["My index page description 1", "My index page description 2"],
  },
};

Ready-to-use example

You can find ready-to-use NextJS example in the example folder.

Installation

npm i generate-content-spreadsheet
  1. Create Google Spreadsheet
  2. Share it publicly (File => Share => Anyone with the link can view)
  3. Add Webpack plugin
  4. Seen plugin generates source file with content
  5. Import and use it in your front-end code
  6. Update spreadsheet and recompile your code
  7. ...
  8. Profit!

FAQ

Why?

I needed a simple way to manage content for my NextJS website. I wanted to use Google Spreadsheet as a CMS, but I didn't want to use any of the existing solutions, because they were either too complicated or too expensive.

Why not use Headless CMS?

If you have lots of images, videos, or other files, then you will need to use fully featured CMS. But if you only need to manage simple text content, then you can use this package.

I am getting wrong columns

  • Make sure you have "key" and "value" columns in your spreadsheet. If you have different column names, then you can change them in the plugin options.
  • Make sure your content is forced to be TEXT. If you have numbers, Google Sheets returns wrong data.

License

MIT License (c) 2023 Ruslan Gainutdinov