Skip to Content
Environment variables

Configuration

Rotion is configured with environment variables, or in code with configure. The variables are read each time Rotion uses them, so they only have to be set before the first fetch: in .env.local for Next.js, in the CI job’s environment, or on the command line.

NOTION_TOKEN=ntn_xxx ROTION_INCREMENTAL_CACHE=true npm run build

Variables

NameDefaultDescription
NOTION_TOKENnone (required)Secret of the Notion integration. Every API request uses it.
GOOGLEMAP_KEYnoneGoogle Maps Embed API key. Needed to turn a Google Maps link in an embed block into a map; without it the map is not embedded.
ROTION_CACHEDIR.cacheDirectory for cached API responses and lock files.
ROTION_INCREMENTAL_CACHEfalsetrue refetches databases after ROTION_CACHE_AVAILABLE_DURATION, and pages and blocks when the last_edited_time you pass differs from the cached one. Otherwise an existing cache is always used. See Caching.
ROTION_CACHE_AVAILABLE_DURATION120000 (ms, 2 minutes)How long a cached database query is used before it is sent again, with the incremental cache on. Also how long the cached lookups for page properties, databases and breadcrumbs are used, in either mode.
ROTION_DOCROOTpublicDirectory that is served as the site root. Downloaded images and files go below it.
ROTION_IMAGEDIRimagesDirectory for images, relative to ROTION_DOCROOT. Also the first segment of the image paths in the data (/images/...).
ROTION_FILEDIRfilesDirectory for files, PDFs and videos, relative to ROTION_DOCROOT. Also the first segment of their paths (/files/...).
ROTION_WEBP_QUALITY95Quality (1–100) of the WebP images converted from downloads. 0 skips the conversion.
ROTION_WAITTIME0 (ms)Pause after every successful Notion API request.
ROTION_LIMITED_WAITTIME60000 (ms, 1 minute)Pause before retrying a request that failed with a rate limit, a server error or a timeout. A request is tried up to three times.
ROTION_TIMEOUT1500 (ms)Idle timeout of the HTTP requests Rotion makes itself: file downloads and fetching pages for bookmarks and embeds. Not used for Notion API requests.
ROTION_MAX_REDIRECTS5Maximum number of redirects followed by those HTTP requests.
ROTION_UA<name>/<version> of the package.json in the current directory, or rotion without oneUser-Agent header of those HTTP requests. Some sites answer differently depending on it; Rotion’s own site builds with ROTION_UA=curl.
ROTION_SKIP_QUERY_VALIDATIONfalsetrue sends database queries without checking the filter and sorts first. See validateQuery.
ROTION_STRICTfalsetrue throws on the first failure to fetch a part of a page, such as an image, instead of printing a warning and leaving it out. Third-party extras (bookmarks, embeds, link previews) only warn. See Failed requests.
ROTION_DEBUGfalsetrue logs cache decisions and lock activity, prints the whole error after each warning, and sets the Notion client’s log level to debug. Failures are printed without it.
ROTION_SKIP_DOWNLOADfalsetrue returns image paths without downloading the images. Intended for Rotion’s tests.

Boolean variables are enabled only by the exact string true. Numeric values are parsed as integers.

Paths in ROTION_CACHEDIR and ROTION_DOCROOT are relative to the current working directory, and so is the package.json that gives the default ROTION_UA.

Configure in code

configure sets the same settings from code. A value given to it wins over its environment variable. Use it when environment variables are inconvenient: a framework that does not put .env into process.env, such as Astro’s import.meta.env, or a token that comes from somewhere else.

import { configure } from 'rotion' configure({ auth: import.meta.env.NOTION_TOKEN, docRoot: 'storage', incrementalCache: true, })

Call it before the first fetch. A later call adds to the earlier ones, and undefined goes back to the environment variable. The settings are process-wide.

OptionVariable
authNOTION_TOKEN
cacheDirROTION_CACHEDIR
docRootROTION_DOCROOT
imageDirROTION_IMAGEDIR
fileDirROTION_FILEDIR
incrementalCacheROTION_INCREMENTAL_CACHE
cacheAvailableDurationROTION_CACHE_AVAILABLE_DURATION
waitTimeROTION_WAITTIME
limitedWaitTimeROTION_LIMITED_WAITTIME
timeoutROTION_TIMEOUT
webpQualityROTION_WEBP_QUALITY
maxRedirectsROTION_MAX_REDIRECTS
userAgentROTION_UA
googleMapKeyGOOGLEMAP_KEY
skipQueryValidationROTION_SKIP_QUERY_VALIDATION
strictROTION_STRICT
debugROTION_DEBUG

Variables used by the examples

NOTION_DATABASE_ID, used throughout these docs and in the examples, is not read by Rotion. The examples read it in their own code and pass it to FetchDatabase.

Last updated on