Package Exports
- notion-to-post
Readme
Notion to Post
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 missingPublished
(checkbox) - Required for filtering published postsCreated
(date) - Required for sortingDescription
(rich text) - OptionalSlug
(formula) - OptionalTags
(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 sluggetFormattedPostByTitle(databaseId: string, title: string)
: Get a single post by titlegetFormattedPosts(databaseId: string)
: Get all published postsgetPosts(databaseId: string)
: Get all posts without markdown content
License
MIT