JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q63012F
  • License MIT

Package Exports

  • notion-to-post

Readme

Notion to Post

npm version

Notion Post is a TypeScript library for fetching and converting Notion database pages into markdown format, making it easy to use Notion as a headless CMS for blogs or static sites.

Features

  • Retrieve posts from a Notion database
  • Convert Notion blocks to markdown
  • Access post metadata and properties
  • Filter and format posts by slug or title
  • Support for pagination and sorting
  • ESM and CommonJS support

Prerequisites

  • Notion API key
  • Notion database with the following properties:
    • Name (title) - Required, defaults to "Untitled" if missing
    • Published (checkbox) - Required for filtering published posts
    • Created (date) - Required for sorting
    • Description (rich text) - Optional
    • Slug (formula) - Optional
    • Tags (multi-select) - Optional

Installation

npm install notion-to-post

Usage

import { getFormattedPostBySlug, getFormattedPosts } from "notion-to-post";

// Initialize with your Notion API key
process.env.NOTION_API_KEY = "your-notion-api-key";

// Get a single post by slug
const post = await getFormattedPostBySlug("your-database-id", "your-post-slug");
console.log(post.title, post.markdown);

// Get all published posts
const posts = await getFormattedPosts("your-database-id");

API Reference

  • getFormattedPostBySlug(databaseId: string, slug: string): Get a single post by slug
  • getFormattedPostByTitle(databaseId: string, title: string): Get a single post by title
  • getFormattedPosts(databaseId: string): Get all published posts
  • getPosts(databaseId: string): Get all posts without markdown content

License

MIT