UNPKG

@jitl/notion-api

Version:

The missing companion library for the official Notion public API.

56 lines (55 loc) 1.73 kB
/** * Tools for building up a set of backlinks in-memory, because the API doesn't * provide backlink information yet. * @category Backlink * @module */ import { PageWithChildren, RichTextToken } from './notion-api'; /** * Where a page was mentioned from * @category Backlink */ export interface BacklinkFrom { mentionedFromPageId: string; mentionedFromBlockId: string; } /** * A link from one block to another page. * @category Backlink */ export interface Backlink extends BacklinkFrom { mentionedPageId: string; } /** * @category API */ export declare function isNotionDomain(domain: string): boolean; /** * Records links from a page to other pages. * See [[buildBacklinks]]. * @category Backlink */ export declare class Backlinks { linksToPage: Map<string, Backlink[]>; private pageLinksToPageIds; add(args: Backlink): Backlink; maybeAddUrl(url: string, from: BacklinkFrom): Backlink | undefined; maybeAddTextToken(token: RichTextToken, from: BacklinkFrom): Backlink | undefined; getLinksToPage(pageId: string): Backlink[]; /** * When we re-fetch a page and its children, we need to invalidate the old * backlink data from those trees */ deleteBacklinksFromPage(mentionedFromPageId: string): void; } /** * Crawl the given `pages` and build all the backlinks between them into `backlinks`. * If no [[Backlinks]] is given, a new one will be created and returned. * @category Backlink */ export declare function buildBacklinks(pages: PageWithChildren[], backlinks?: Backlinks): Backlinks; /** * Ensure a UUID has dashes, since sometimes Notion IDs don't have dashes. * @category API */ export declare function uuidWithDashes(id: string): string;