Giter Club home page Giter Club logo

notion-graph's Introduction

notion

logo.png

npm i --save @graphcentral/notion-graph-scraper

You will be able to visualize the output from @graphcentral/notion-graph-scraper with @graphcentral/graph like below: doc1.png

Example

First, get a public Notion page (if you just want to test it out), preferably with some sub-pages inside it, so that you can get a graph with some nodes. You can also request private pages if you create your own instance of NotionAPI from notion-client. The example below is only for public pages.

Then, get the id of the page like below:

doc0.png

Then, input the id of the page as a parameter to notionGraph.buildGraphFromRootNode

import { NotionGraph } from "@graphcentral/notion-graph-scraper"
import fs from "fs"
/**
 * example of how to use `@graphcentral/notion-graph-scraper`
 */
;(async () => {
  const notionGraph = new NotionGraph({
    maxDiscoverableNodes: 2000,
    maxDiscoverableNodesInOtherSpaces: 2000,
    verbose: true,
  })
  const graph = await notionGraph.buildGraphFromRootNode(
    // Some random Japanese blog
    `95fcfe03257541c5aaa21dd43bdbc381`
  )
  console.log(graph.nodes.length)
  console.log(graph.links.length)
  await new Promise((resolve, reject) => {
    fs.writeFile(`test0.json`, JSON.stringify(graph), (err) => {
      if (err) reject(err)
      else resolve(``)
    })
  });

  process.exit(0)
})()

The graph will be an object of this type:

{
  nodes: Node[]
  links: Link[]
  errors: Error[]
}

Then, you can directly use this as an input to @graphcentral/graph to visualize it on the web as a force layout graph.

Example setup

An example setup is at @graphcentral/notion-scrape-example.

Use ES6 module instead of Commonjs

This project uses es6 module (.mjs). Therefore, the following setup is needed:

In your package.json, specify "type" as "module"

{
  ...
  "type": "module",
  ...
}

Then, using the latest version of node (this project uses whatever is specified in .nvmrc which is as of now v16.15.1), just run node index.js where index.js contains the previous example code.

notion-graph's People

Contributors

9oelm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.