UNPKG

motionlink-cli

Version:

Making it easy to use Notion as a Content Management system for personal websites, portfolios, blogs, business homepages, and other kinds of static websites.

107 lines (106 loc) 3.95 kB
import { GetBlockResponse, GetDatabaseResponse, GetPageResponse } from '@notionhq/client/build/src/api-endpoints'; import { FileObject } from './notion_objects'; export declare type NotionBlock = { data: GetBlockResponse; children: NotionBlock[]; }; export declare type NotionPage = { otherData: Record<string, any>; data: GetPageResponse; blocks: NotionBlock[]; /** * This value should be retrieved by users in DatabaseRule.map. * Default is page id. */ _title?: string; }; export declare type NotionDatabase = { pages: NotionPage[]; data: GetDatabaseResponse; }; export declare type Context = { /** * Object containing the `NotionDatabase`s pulled with the `DatabaseRule`s * in `alsoUses` of this `TemplateRule`. * * For example, `others.abc` will contain the `NotionDatabase` fetched by * the `DatabaseRule` in this `TemplateRule.alsoUses` whose `database` field is * `abc`. It will be undefined if there is no such `DatabaseRule`. */ others: Record<string, NotionDatabase>; /** * Transforms the given blocks to markdown with the `BlockTransformers` in * `services/markdown_service`. * * The output of this function is nor formatted. * * You can modify the `BlockTransformers` and `ObjectTransformers` objects * to provide custom transformers or otherwise add new transformers. For * example, running `ObjectTransformers.equation = (object) => 'No Inline Equations'` * will cause `genMarkdownForBlocks` to render `'No Inline Equations'` whenever an inline * equation object is encountered while generating the markdown. * * Likewise, modify `BlockTransformers` to provide custom transformers for entire blocks. * For example: * * @example * const markdownService = require('motionlink-cli/lib/services/markdown_service'); * const ObjectTransformers = markdownService.ObjectTransformers; * * ObjectTransformers.equation = (block) => '**No Equations allowed on this site!**'; * * // ... */ genMarkdownForBlocks: (blocks: NotionBlock[]) => string; /** * Returns the download url and caption for the given FileObject. * * If the media is hosted by Notion, it will be downloaded to a media folder in the * `outDir` of this TemplateRule and the returned `src` value will be the asset path * in `outDir`, else the file url will be returned as is given in the media object. * * The return value of this function is not affected by the value of * `TemplateRule.writeMediaTo`. */ fetchMedia: (object: FileObject) => { src: string; captionMarkdown: string; }; }; declare type T = { property: string; direction: 'ascending' | 'descending'; } | { timestamp: 'created_time' | 'last_edited_time'; direction: 'ascending' | 'descending'; }; export declare type SortsParams = T[]; export declare type DatabaseRule = { database: string; fetchBlocks?: boolean; takeOnly?: number; map?: (notionPage: NotionPage, context: Context) => NotionPage; sort?: SortsParams; /** * See: https://developers.notion.com/reference/post-database-query#post-database-query-filter */ filter?: object; }; export declare type TemplateRule = { template: string; outDir: string; uses: DatabaseRule; alsoUses: DatabaseRule[]; /** * The folder to write media assets to. * * By default media is placed in the same folder as the page requesting it. Setting this field * forces the media to be placed in this folder. * * Do note, however, that `Context.fetchMedia` will will return the path of the media * as if it were in the same folder as the page requesting it, i.e setting this value * does not affect the return value of `Context.fetchMedia`. */ writeMediaTo?: string; }; export {};