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

@agency-kit/notion-cms

v0.10.0

Published

Turn Notion into a full-fledged headless content management system.

Downloads

57

Readme

notion -_  notionCMS  -_ prod

Features

🏗️  Framework agnostic - it’s just JS.
🌲 Build a collection-based CMS tree from your Notion database.
🎚️ Leverage database structure to control your routing structure.
⚙️ Geared for Static Site Generation.
📑  Transform Notion blocks → Markdown, plaintext, and (customizable) html.
🗃️ Optimized Content Caching for super fast builds.
🧩 Plugin ready with some powerful core plugins on the way.
🦾 Tagging, filtering, path queries, and tree-walking utilities.
⌨️ Totally Typesafe.

Install

npm install @agency-kit/notion-cms
pnpm add @agency-kit/notion-cms
yarn add @agency-kit/notion-cms

Why.

Notion excels at managing content. It also has a great API and SDK. But why is it so challenging to actually leverage Notion as a CMS (Content Management System) in production?

Until recently there wasn't support for sub-pages (sub-items in a database) in Notion. So most existing Notion-as-a-cms solutions don't provide a way to leverage this new feature, which turns out to be crucial for building a collection-based CMS. Another barrier is that pulling content from Notion can be time consuming. Responses can take a few seconds at times, the API provides a lot of data to sift through, and multiple calls to different endpoints are required in order to go from CMS database to the content for each page. All of this together results in a less than excellent developer experience when using a static site generator that often makes requests on each build.

NotionCMS exists to address each of these issues and provide an excellent developer experience while using Notion as your Content Management System.

The Database Structure

In order to make use of NotionCMS, you have to subscribe to a specific database structure. Its an extremely generic design that gives you all the things you need for basic sites but lends flexibility for types of content other than the standard web page, blog post etc.

See the structure in this template this template.

Basic Usage


// initialize
const myCoolCMS = new NotionCMS({
  databaseId: 'e4fcd5b3-1d6a-4afd-b951-10d56ce436ad',
  notionAPIKey: process.env.NOTION,
  // Other options
})

// Pull down all Notion content
await myCoolCMS.pull()

// Access the routes here:
console.log(myCoolCMS.routes)

// Access the page content here:
console.log(myCoolCMS.data)

// Access paths like this:
const postA = myCoolCMS.data['/posts']['/how-to-build-a-blog-with-notion']
const postB = myCoolCMS.data['/posts']['/how-to-use-notion-cms']

Advanced Usage


const customPlugin = () => {
  return {
    name: 'my-custom-plugin',
    hook: 'pre-parse', // other option is 'post-parse'
    // list of blocks to transform.
    // If hook is post parse, its the string of html parsed from blocks
    exec: (blocksOrHtml) => {
      // do some transformations,
      const transformedBlocksOrHtml = someXform(blocksOrHtml)
      return transformedBlocksOrHtml
    }
  }
}

const myAdvancedCMS = new NotionCMS({
  databaseId: 'e4fcd5b3-1d6a-4afd-b951-10d56ce436ad',
  notionAPIKey: process.env.NOTION,
  rootUrl: 'https://mycoolsite.com',
  localCacheDirectory: `${process.cwd()}/localcache/`,
  refreshTimeout: '1 hour',
  plugins: [customPlugin()],
})

await myAdvancedCMS.pull()

See the full API reference.

Some Helper methods

// returns page reference
myCMS.queryByPath('/full/path/to/page')

// returns an array of only child pages of a page looked up using the key.
// This runs queryByPath under the hood so you can save a step
myCMS.filterSubPages('/full/path/to/page' /* or Page reference*/)

// returns page object without any children - just the content. Useful for serializing and sending a
// single pages data to the client.
myCoolCMS.rejectSubPages('/full/path/to/page' /* or Page reference*/)

// Get tagged collections this way or by passing a single tag:
const tagged = myCoolCMS.getTaggedCollection(['blog', 'programming'])

// walk the CMS from the root node and perform some operation for each node.
// the node parameter will be of type PageContent so you have access to all of the page data
myCoolCMS.walk(node => console.log(node), '/partial/path/to/start')

// for async callbacks
await myCoolCMS.asyncWalk(async node => await asynchronousFunc())

Project Stats

Alt