UNPKG

@inkdropapp/live-export

Version:

A library for programmatically exoprting notes to local filesystem from Inkdrop

114 lines (113 loc) 3.58 kB
import { Note, File as IDFile, Tag } from 'inkdrop-model'; import { YAML, Image as ImageNode, Root } from 'mdast'; type YAMLData = Record<string, any>; interface LiveExportConfig { hostname?: string; username: string; password: string; port: number; } interface ExportParams { live?: boolean; bookId: string; since?: number; /** * Generate a path to export the specified note */ pathForNote: (data: { note: Note; frontmatter: YAMLData; tags: Tag[]; }) => string | undefined | null | false | Promise<string | undefined | null | false>; /** * Generate a URL for the specified note. * It is necessary to link from the note to another note. */ urlForNote?: (data: { note: Note; frontmatter: YAMLData; tags: Tag[]; }) => string | undefined | null | false | Promise<string | undefined | null | false>; /** * Generate a path and URL to export the specified image file */ pathForFile: (data: { mdastNode: ImageNode; note: Note; file: IDFile; extension: string; frontmatter: YAMLData; tags: Tag[]; }) => { filePath: string; url: string; } | undefined | null | false | Promise<{ filePath: string; url: string; } | undefined | null | false>; /** * Pre-process the specified note. * It is useful to update the frontmatter information based on the note metadata. */ preProcessNote?: (data: { note: Note; frontmatter: YAMLData; tags: Tag[]; mdast: Root; }) => any | Promise<any>; /** * Post-process the specified note right before writing the note to a file. * It is useful to tweak the Markdown data (e.g., deleting unnecessary lines). * * @returns The processed Markdown data */ postProcessNote?: (data: { md: string; frontmatter: YAMLData; tags: Tag[]; }) => string | Promise<string>; } export declare const extractDocIdFromUri: (uri: string) => string | undefined; export declare class LiveExporter { config: LiveExportConfig; fileNameMap: { [id: string]: string; }; tagMap: { [id: string]: Tag; }; constructor(config: LiveExportConfig); callApi(path: string, query?: Record<string, any>): Promise<any>; getLatestSeq(): Promise<number>; getChanges(since: number): Promise<any>; getNotes(bookId: string): Promise<Note[]>; getTags(): Promise<Tag[]>; getTagsWithIds(ids: string[]): Promise<Tag[]>; getDoc(docId: string, options?: Record<string, any>): Promise<any>; getExtensionForFile(file: IDFile): string; writeFile(toPath: string, file: IDFile): void; writeNote(toPath: string, noteId: string, md: string): void; removeExportedFile(docId: string): void; parseNote(note: Note, params: ExportParams): Promise<{ note: Note; tree: Root; yamlNode: YAML | undefined; yamlData: any; tags: Tag[]; }>; exportNote(note: Note, params: ExportParams): Promise<void>; watchChanges(params: ExportParams): Promise<{ stop: () => void; }>; start(params: ExportParams & { live: true; }): Promise<{ stop: () => void; }>; start(params: ExportParams & { live: undefined | false; }): Promise<true>; } export declare const kebabCaseToPascalCase: (string?: string) => string; export declare const toKebabCase: (str: string) => string | undefined; export {};