Convert Notion.so pages into NAST representation, using Notion's API.
npm i nast-util-from-notionapi
Also need notionapi-agent
to retrieve raw data from Notion's API.
npm i notionapi-agent
require
this module,
const { getOnePageAsTree, getAllBlocksInOnePage } = require('nast-util-from-notionapi')
const fs = require('fs')
const NotionAgent = require('notionapi-agent')
const { getOnePageAsTree, getAllBlocksInOnePage } = require('nast-util-from-notionapi')
/* Configure NotionAgent's options */
const options = {
token: '',
suppressWarning: false,
verbose: true
}
const agent = new NotionAgent(options)
async function main() {
try {
/* Fill in a page ID */
let pageID = ''
let tree = await getOnePageAsTree(pageID, agent)
let rawBlocks = await getAllBlocksInOnePage(pageID, agent)
fs.writeFileSync(
`PageTree-${pageID}.json`,
JSON.stringify(tree),
{ encoding: 'utf-8' }
)
fs.writeFileSync(
`RawBlocks-${pageID}.json`,
JSON.stringify(rawBlocks),
{ encoding: 'utf-8' }
)
} catch (error) {
console.error(error)
}
}
main()
Download a page as a tree object in an easier-to-work-with format.
-
pageID
- (required) The ID of a Notion page. It must be the one with dashes as below :cbf2b645-xxxx-xxxx-xxxx-xxxxe8cfed93
-
agent
- (required) Anotionapi-agent
-compatible instance. You can just use thenotionapi-agent
package.
A tree consists of NAST.Block
nodes.
interface NAST.Block {
uri: URI
type: string
color?: string
createdTime: TimestampNumber
lastEditedTime: TimestampNumber
children: NAST.Block[]
}
Download all blocks of a page in Notion's record format.
Function parameters are the same as getOnePageAsTree
.
Notion.BlockRecord[]
, where the role
property of every Notion.BlockRecord
being a Notion.Role, and value
property of every Notion.BlockRecord
being a Notion.Block
[
{
role: Notion.Role
value: Notion.Block
}
]
Generated by dependency-cruiser
NPM package.
Before NAST is redesigned to have better representation of links and references, alias
blocks (created by "Link to page" since some day in June or July, 2021) are dereferenced to page
blocks, transclusion_container
block and transclusion_reference
block are dereferenced to their content.