Giter VIP home page Giter VIP logo

notion-cms's Introduction

notion-cms

Script to use Notion as CMS for Gatsby website.

Description

The script

  1. uses the newly released Notion API to retrieve posts from a Notion database with the status "Publish",
  2. converts the posts to Markdown (as best it can, see "Limitations") and saves them into the local blog directory,
  3. adds and commits all new posts to GitHub and then pushes them to their repository,
  4. and updates their statuses in Notion to "Published".

Since my Gatsby site is deployed through GitHub and Netlify, the site is then rebuilt with the new posts.

I set the script on a timer and then installed it as a Windows service so that it always runs in the background.

Setup and installation

Requirements

Your machine will need Node.js and Git installed and a local Git repository for the blog in question. For more information about Git requirements, see here.

Steps

  1. Clone this repository on your local machine and run npm install to install all relevant modules.
  2. If you want to use it as a Windows service, also run npm link node-windows.
  3. Create an .env file with the following variables:
  • NOTION_TOKEN: Internal integration token provided by Notion
  • NOTION_DATABASE_ID: ID for database to query for posts - you can use this function to find it
  • BLOG_DIRECTORY: Path to local GitHub repository for your blog - this is where Git commands will run from
  • POSTS_DIRECTORY: Path from blog directory to wherever posts should be saved - this should just be something like src\posts
  1. Review the following settings in index.js:
  • runEveryXMin: How frequently the script should run, in minutes
  • dbFilter: What Notion properties the script should use to filter for new posts - see here
  • dbUpdate: What Notion properties the script should update upon success - see here
  • Other to note: the script pulls these properties from the Notion page, and you'll need to change this if you structure your posts differently: Description (text), Slug (text), Category (select), Tags (multi-select)
  1. To run the script, type npm start.
  2. To set it up as a serivce, type node service.js.

Limitations

Right now, the Notion API has no support for quotes or for codeblocks, and this script has no support for numbered lists.

notion-cms's People

Contributors

juliariec avatar

Stargazers

Sumanth avatar

Watchers

 avatar

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.