Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wonism/get-notion-contents

Get contents from notion
https://github.com/wonism/get-notion-contents

notion notion-contents

Last synced: about 1 month ago
JSON representation

Get contents from notion

Awesome Lists containing this project

README

        

# get-notion-contents
> Get contents from notion

[![NPM](https://img.shields.io/npm/v/get-notion-contents.svg?style=flat)](https://npmjs.org/package/get-notion-contents)
[![Build Status](https://travis-ci.org/wonism/get-notion-contents.svg?branch=master)](https://travis-ci.org/wonism/get-notion-contents)
![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/get-notion-contents.svg)

## Installation
```sh
$ npm i -S get-notion-contents
```

## ⚠️ Prerequisite
You need a token to use this package if you want to get private contents.
You can get it from [Notion.so](https://www.notion.so/) cookie. the key of it is `token_v2`.

## Development
```sh
$ export NOTION_TOKEN="<>"
$ npm start
```

## Return type of methods

#### getUser()
```ts
Promise<{
email: string;
family_name: string;
given_name: string;
id: string;
onboarding_completed: boolean;
profile_photo: string;
version: number;
}>
```

#### getPageIds(skipChildren: boolean = false)
```ts
Promise
```

#### getPageById(id: string)
```ts
Promise<{
id: string;
title: string;
titleString: string;
content: string;
resource?: string;
}>
```

#### getPages()
```ts
Promise>
```

## How to use
```ts
import Notion from 'get-notion-contents';

// create instance of Notion.
const notion = new Notion('<>', { prefix: '<>', removeStyle: false });

(async () => {
// get user information
const user = await notion.getUser();
console.log(user);

// get ids of all pages
const pageIds = await notion.getPageIds();
console.log(pageIds);

// get content of a page
const page = await notion.getPageById(pageIds[0]);
console.log(page);

// get contents of all pages
const pages = await notion.getPages();
console.log(pages);
})();
```

#### Option
- prefix: add prefix into relative links
- removeStyle: remove inline styles

---



Buy Me A Coffee