Socket
Socket
Sign inDemoInstall

rotion

Package Overview
Dependencies
10
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rotion

This is react components that uses the notion API to display the notion's database and page.


Version published
Weekly downloads
10
decreased by-73.68%
Maintainers
1
Created
Weekly downloads
 

Readme

Source




Rotion



Rotion makes it easy to generate a Static Website using React and the Notion API. Therefore, images and other necessary files are stored locally. Basically, it is designed to use Next.js, but it will work with other frameworks as well.

Actions NPM

Example

Take a look at the website built with rotion.

Usage

Use API calls and components together. This is database list example:

import type { GetStaticProps, NextPage } from 'next'
import Link from 'next/link'
import { FetchDatabase, QueryDatabaseResponseEx, QueryDatabaseParameters } from 'rotion'
import { List } from 'rotion/ui'

type Props = {
  db: QueryDatabaseResponseEx
}

export const getStaticProps: GetStaticProps<Props> = async (context) => {
  const db = await FetchDatabase({
    database_id: process.env.NOTION_DBID,
    filter: {
      property: 'Published',
      checkbox: {
        equals: true
      },
    },
    sorts: [
      {
        property: 'Date',
        direction: 'descending'
      },
    ]
  } as QueryDatabaseParameters)

  return {
    props: {
      db,
    }
  }
}

export default const DB: NextPage<Props> = ({ db }) => {
  return (
    <List keys={['Name', 'spacer', 'Tags', 'Date']} db={db} href="/animals/[id]" link={Link} />
  )
}

This is page example:

import type { GetStaticProps, NextPage } from 'next'
import { FetchBlocks, ListBlockChildrenResponseEx } from 'rotion'
import { Page } from 'rotion/ui'

type Props = {
  blocks: ListBlockChildrenResponseEx
}

export const getStaticProps: GetStaticProps<Props> = async (context) => {
  const blocks = await FetchBlocks({ block_id: process.env.NOTION_PAGEID })
  return {
    props: {
      blocks,
    }
  }
}

export default const Page: NextPage<Props> = ({ blocks }) => {
  return (
    <Page blocks={blocks} />
  )
}

Set the notion token as environment variable:

$ cat .env
NOTION_TOKEN=secret_vHVKhIeYm95ga1sjOv*************************
NOTION_PAGEID=23740912-d6ac-4018-ab76-c64e772a342a
NOTION_DBID=81781536-afc6-431d-a217-21177e7bf8e0

Notion ID is UUIDv4 format: 8-4-4-4-12.

Env nameDescriptionDefault
NOTION_TOKEN *requirementRead permission is required in notion's credentials-
ROTION_CACHEDIRCache directory name.cache
ROTION_DOCROOTWeb server root directorypublic
ROTION_IMAGEDIRWeb server image directoryimages
ROTION_INCREMENTAL_CACHEEnable incremental cachefalse
ROTION_WAITTIMEmilliseconds to wait right after api request due to ratelimit0
ROTION_LIMITED_WAITTIMEmilliseconds to wait before backoff after ratelimit limit60sec
ROTION_WEBP_QUALITYQuality for WebP converting95
ROTION_DEBUGLogging level to debug-

API

This is the API available:

  • FetchDatabase: Returns page list and properties in database
  • FetchPage: Returns page title and properties
  • FetchBlocks: Returns blocks that is the content of the page.
  • FetchBreadcrumbs: Returns title and icons for breadcrums

Images are saved in ROTION_IMAGEDIR locally.

Components

This is the components available:

  • Page Blocks
  • Database List View
  • Database Gallery View
  • Database Table View
  • Database Calendar View
  • Database Timeline View

Storybook

Check the display of components in Storybook:

$ npm run story

Author

@linyows

Keywords

FAQs

Last updated on 01 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc