astronotion
Version:
Library to make Astro sites with content from Notion
60 lines (59 loc) • 1.86 kB
TypeScript
/**
* Public path to store downloaded images.
*/
export declare const AN_IMAGES_DIR = "public/images/astronotion";
export declare type Image = {
id: string;
url: string;
};
/**
* Given a full URL, get the image path. Optionally prepend with
* string from preceding path to ensure unique file name.
*
* @param {string} url
* @param {boolean=} prepend
* @returns {string} eg. "cat-in-helmet.jpg"
*/
export declare const getFilename: (url: string, prepend?: boolean) => string;
/**
* Returns true if URL contains an expires header, which means it
* needs to be downloaded to user's directory.
*
* @param {string} url
* @returns {boolean}
*/
export declare const checkShouldDownloadImage: (url: string) => boolean;
/**
* Returns true if URL should be replaced with a downloadable one,
* ie. with an expires header.
*
* @param {string} url
* @returns {boolean}
*/
export declare const checkShouldReplaceDownloadable: (url: string) => boolean;
/**
* Run customization on Notion image URLs, eg. add missing base path,
* add size params, etc.
*
* @param {string} url
* @returns {string}
*/
export declare const customizeImageUrl: (url: string) => string;
/**
* Compare a given image URL with list of downloadable URLs.
* Return a matching downloadable URL (ie. if it's a custom uploaded image)
* or else return the original URL (ie. from Notion gallery, Unsplash, etc).
*
* @param {string} oriUrl
* @param {string[]} downloadableUrls
* @returns string
*/
export declare const replaceImageUrlWithDownloadable: (oriUrl: string, downloadableUrls: string[]) => string;
/**
* Wrapper function for other image helper functions in this module.
*
* @param {string} oriUrl
* @param {string[]=} downloadableUrls
* @returns string
*/
export declare const transformImageUrl: (oriUrl: string, downloadableUrls?: string[]) => string;