0.1.5 • Published 17 days ago

rotion v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

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.

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

0.1.5

17 days ago

0.1.0

21 days ago

0.1.2

20 days ago

0.1.1

20 days ago

0.1.4

20 days ago

0.1.3

20 days ago

0.0.12

3 months ago

0.0.13

3 months ago

0.0.14

3 months ago

0.0.10

3 months ago

0.0.11

3 months ago

0.0.9

3 months ago

0.0.8

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.5

3 months ago

0.0.3

3 months ago

0.0.4

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago