Class ImageHandler<T>

Type Parameters

  • T extends ContentFile = ContentFile

Hierarchy

Constructors

  • Type Parameters

    • T extends ContentFile = ContentFile

    Parameters

    • __namedParameters: {
          cache?: boolean;
          globs: string[];
          outputPath: string;
          permalink?: string | ((slug: string, filepath: string) => string);
          sizeSuffix?: ((width: number, height: number) => string);
          sizesProperty?: string;
          type?: string;
          widths?: number[];
      }
      • Optional cache?: boolean

        Whether to enable the cache. If an image is found in the cache that satisfies the necessary sizes, it will not be reprocessed/copied.

      • globs: string[]
      • outputPath: string

        The output path. Note this is cleaned of unknown images.

      • Optional permalink?: string | ((slug: string, filepath: string) => string)

        The permalink base, e.g. /resources/, in which case the permalinks will look like /resources/slug or a function that returns the permalink.

      • Optional sizeSuffix?: ((width: number, height: number) => string)
          • (width: number, height: number): string
          • The size suffix to add to resized files, the default is _{WIDTH}w

            Parameters

            • width: number
            • height: number

            Returns string

      • Optional sizesProperty?: string

        For setting the sizes property for use with srcset on images. Since what you want might vary, this is not automatically generated and should be changed depending on the layout.

        The default is 700px images at 700px or wider since that is what I limit my post widths to, otherwise the image is at nearly 100vw and the appropriate size should be chosen.

      • Optional type?: string

        The type to set for files processed by this plugin. The default is image.

      • Optional widths?: number[]

        A list of widths to resize to.

        If the image is smaller than the width specified it is NOT created and it will be copied WITHOUT a suffix.

        If the image is bigger than the largest width specified, the original will NOT be copied, and it will only exist suffixed.

        The default is [400, 700, 1000] which I find are good sizes. 400 for mobile, 700 is the max post width, 1000 is for if the user wants to see a more high def picture.

    Returns ImageHandler<T>

Properties

cache: {
    dirs: Record<string, true>;
    images: Record<string, ContentFile>;
} = ...

The cache should be an object and it should not be re-assigned to (i.e. do no do this.cache = ... after constructing) or the server will loose track of it and will not write/load it from disk.

Type declaration

  • dirs: Record<string, true>
  • images: Record<string, ContentFile>
cacheEnabled?: boolean = true
globs: string[]
name: string
outputPath: string
sizesProperty: string = ...
type: string = "image"
widths: number[] = ...

Methods

  • Parameters

    • metadata: Omit<MakeOptional<ContentMetadata, "publish" | "tags">, "extra"> & Record<string, any>

    Returns ContentMetadata

  • Parameters

    • slug: string
    • filepath: string

    Returns string

  • Should do the initial entry parsing and partially "resolve" any relative paths and wiki/obsidian like paths.

    See ContentEntry for what it needs to return.

    It should also keep a reference to the parsed tree if there is any, such that it can be changed to resolve/unresolve links and get recompiled without reparsing it.

    Parameters

    • filepath: string
    • Optional stats: Stats

    Returns Promise<ContentEntry<T>>

  • Given an entry and a link map (Record<link, {id, permalink}>), should return a list of ids it could resolve if it is a type of file that can resolve them.

    The default implementation returns an empty array.

    Parameters

    • entry: InternalContentEntry<T>
    • linkMap: LinkMapperResolve

    Returns Promise<string[]>

  • Given an entry and a link map (Record<permalink, {id, link}>), should return a list of ids it could unresolve (change back from permalinks to link, the original resolved path) if it is a type of file that can resolve links.

    The default implementation returns an empty array.

    Parameters

    • entry: InternalContentEntry<T>
    • linkMap: LinkMapperUnResolve

    Returns Promise<string[]>

Generated using TypeDoc