@types/metalsmith

  • Version 2.3.1
  • Published
  • 19.5 kB
  • 1 dependency
  • MIT license

Install

npm i @types/metalsmith
yarn add @types/metalsmith
pnpm add @types/metalsmith

Overview

TypeScript definitions for metalsmith

Index

Functions

function Metalsmith

Metalsmith: (directory: string) => Metalsmith;
  • Initialize a new Metalsmith builder with a working directory.

    Parameter directory

    The working directory.

    Example 1

    initialize Metalsmith with the node.js working directory Metalsmith(__dirname); [Metalsmith] http://www.metalsmith.io/ [API] https://github.com/metalsmith/metalsmith#new-metalsmithdir [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L30

Interfaces

interface File

interface File {}
  • Metalsmith representation of a file

property contents

contents: Buffer;
  • A Node Buffer that can be .toString'ed to obtain its human-readable contents

property mode

mode?: string;
  • Octal permission Mode of a file

property stats

stats?: Stats;

index signature

[property: string]: any;

    interface Files

    interface Files {}
    • Metalsmith representation of the files in metalsmith.source(). The keys represent the file paths and the values are Metalsmith.File objects

    index signature

    [filepath: string]: File;

      interface Metalsmith

      interface Metalsmith {}

        property ignores

        readonly ignores: string[];
        • The (read-only) list of ignores of the current metalsmith instance

        property plugins

        readonly plugins: Metalsmith.Plugin[];
        • The (read-only) list of plugins use'd by the current metalsmith instance. When read from inside a plugin, the list is guaranteed to be complete

        method build

        build: (fn?: Metalsmith.Callback) => object;
        • Perform the build with the current settings outputting to the destination directory.

          Parameter fn

          Optional **(but strongly encouraged)** Callback function.

          Example 1

          Perform the build with the current settings Metalsmith(__dirname).build( function (err: Error): any { if (err) {throw err;} }); [API] https://github.com/metalsmith/metalsmith#buildfn [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L184

        method clean

        clean: { (clean: boolean): Metalsmith; (): boolean };
        • Set whether the destination directory will be cleaned before writing.

          Parameter clean

          [clean=true] - Flag to clean destination directory.

          Example 1

          Set the flag to clean the destination directory to false Metalsmith(__dirname).clean(false); [API] https://github.com/metalsmith/metalsmith#cleanboolean [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L132

        • Get the flag on whether the destination directory will be cleaned before writing.

          Example 1

          Retrieve the clean flag indicating destination directory removal var clean:boolean = Metalsmith(__dirname).clean(); [API] https://github.com/metalsmith/metalsmith#cleanboolean [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L132

        method concurrency

        concurrency: { (max: number): Metalsmith; (): number };
        • Set the maximum number of files to open at once.

          Parameter max

          [max=Infinity] - The maximum number of open files.

          Example 1

          Set the maximum number of files to open at once to 50 Metalsmith(__dirname).concurrency(50); [API] https://github.com/metalsmith/metalsmith#concurrencymax [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L118

        • Get the maximum number of files to open at once.

          Example 1

          Retrieve the maximum number of files to open at once var max:number = Metalsmith(__dirname).concurrency(); [API] https://github.com/metalsmith/metalsmith#concurrencymax [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L118

        method destination

        destination: { (path: string): Metalsmith; (): string };
        • Set the path of the destination directory.

          Parameter path

          [path='build'] - Relative or absolute destination directory path.

          Example 1

          Set the relative destination directory to './build' (the default) Metalsmith(__dirname).destination("build");

          Example 2

          Set the absolute destination directory to 'C:\Projects\Out' Metalsmith(__dirname).destination("C:\\Projects\\Out"); [API] https://github.com/metalsmith/metalsmith#destinationpath [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L104

        • Get the absolute path of the destination directory.

          Example 1

          Retrieve the absolute destination directory path var dst:string = Metalsmith(__dirname).destination(); [API] https://github.com/metalsmith/metalsmith#destinationpath [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L104

        method directory

        directory: { (directory: string): Metalsmith; (): string };
        • Set the path of the working directory.

          Parameter directory

          Relative or absolute working directory path.

          Example 1

          Set the relative working directory to './working' Metalsmith(__dirname).directory("working");

          Example 2

          Set the absolute working directory to 'C:\Projects\Metalsmith' Metalsmith(__dirname).directory("C:\Projects\Metalsmith"); [API] https://github.com/metalsmith/metalsmith#api [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L62

        • Get the absolute path of the working directory

          Example 1

          Retrieve the absolute working directory path const mwd:string = Metalsmith(__dirname).directory(); [API] https://github.com/metalsmith/metalsmith#api [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L62

        method frontmatter

        frontmatter: { (frontmatter: boolean): Metalsmith; (): boolean };
        • Set the flag on whether to parse YAML frontmatter

          Parameter frontmatter

          [frontmatter=true] - Flag to parse YAML frontmatter.

          Example 1

          Set the flag to parse YAML frontmatter to false Metalsmith(__dirname).frontmatter(false); [API] https://github.com/metalsmith/metalsmith#frontmatterboolean [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L145

        • Get the flag on whether to parse YAML frontmatter

          Example 1

          Retrieve the frontmatter flag indicating YAML parsing var parse:boolean = Metalsmith(__dirname).frontmatter(); [API] https://github.com/metalsmith/metalsmith#frontmatterboolean [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L145

        method ignore

        ignore: {
        (
        files: string | string[] | Metalsmith.Ignore | Metalsmith.Ignore[]
        ): Metalsmith;
        (): string[];
        };
        • Set the Ignore files/paths from being loaded into Metalsmith.

          Parameter files

          The file(s) or directories to ignore.

          Example 1

          Add an ignore file to prevent load into Metalsmith Metalsmith(__dirname).ignore("corrupted.html");

          Example 2

          Add an ignore function to prevent load into Metalsmith Metalsmith(__dirname).ignore(ignore(function (filepath: string, stats: Stats) { return stats.isDirectory() && path.basename(filepath) === 'nested'; }); [API] https://github.com/metalsmith/metalsmith#ignorepath [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L159

        • Get the array of Ignored files/paths.

          Example 1

          Retrieve the ignored array of files in Metalsmith var ignored:string[] = Metalsmith(__dirname).ignore(); [API] https://github.com/metalsmith/metalsmith#ignorepath [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L159

        method metadata

        metadata: { (metadata: object): Metalsmith; (): object };
        • Set the global metadata object to pass to templates.

          Parameter metadata

          The global metadata (json).

          Example 1

          Add 'sitename' to the global metadata object Metalsmith(__dirname).metadata({sitename: "My Static Site"}); [API] https://github.com/metalsmith/metalsmith#metadatajson [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L76

        • Get the global metadata object passed to templates.

          Example 1

          Retrieve the metadata object passed to templates var meta:object = Metalsmith(__dirname).metadata(); [API] https://github.com/metalsmith/metalsmith#metadatajson [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L76

        method path

        path: (...paths: string[]) => string;
        • Resolve paths relative to the root directory.

          Parameter paths

          The paths to resolve.

          Example 1

          Retrieve the path after resolving sub-directies var path:string = Metalsmith(__dirname).path("path-a", "path-b"); [API] https://github.com/metalsmith/metalsmith#pathpaths [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L171

        method process

        process: (fn?: Metalsmith.Callback) => object;
        • Process files through plugins without writing out files.

          Parameter fn

          Optional Callback function.

          Example 1

          Process the files like build without writing any files Metalsmith(__dirname).process( function (err: Error): any { if (err) {throw err;} }); [API] https://github.com/metalsmith/metalsmith#processfn [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L200

        method read

        read: {
        (dir: string, fn?: Metalsmith.Callback): object;
        (fn: Metalsmith.Callback): object;
        };
        • Read a dictionary of files from a dir, parsing frontmatter. If no directory is provided, it will default to the source directory.

          Parameter dir

          Optional dictionary of files.

          Example 1

          Read a dictionary of files from a dir. var files:object = Metalsmith(__dirname).read("subdir"); [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L227

        • Read a dictionary of files from a dir, parsing frontmatter. If no directory is provided, it will default to the source directory.

          Parameter fn

          Optional Callback function.

          Example 1

          Read a dictionary of files from a dir. var files:object = Metalsmith(__dirname).read("subdir"); [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L227

        method readFile

        readFile: (file: string) => object;
        • Read a file by path. If the path is not absolute, it will be resolved relative to the source directory.

          Parameter file

          The file path.

          Example 1

          Read a file by path. var fileData:object = Metalsmith(__dirname).readFile("a.html"); [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L261

        method run

        run: {
        (files: object, fn?: Metalsmith.Callback): object;
        (
        files: object,
        plugins: Metalsmith.Plugin[],
        fn?: Metalsmith.Callback
        ): object;
        };
        • Run a set of files through the plugins stack.

          Parameter files

          The dictionary of files.

          Parameter fn

          Optional Callback function.

          Example 1

          Run all of the middleware functions on a dictionary of files. var callback:Metalsmith.Callback = (err: Error, files: object) => {if (err) {throw err;}}; Metalsmith(__dirname).run({fileA: "a.html"} , callback); [API] https://github.com/metalsmith/metalsmith#runfiles-fn [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L212

        method source

        source: { (path: string): Metalsmith; (): string };
        • Set the path of the source directory.

          Parameter path

          [path='src'] - Relative or absolute source directory path.

          Example 1

          Set the relative source directory to './src' (the default) Metalsmith(__dirname).source("src");

          Example 2

          Set the absolute source directory to 'C:\Projects\Site' Metalsmith(__dirname).source("C:\\Projects\\Site"); [API] https://github.com/metalsmith/metalsmith#sourcepath [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L90

        • Get the absolute path of the source directory.

          Example 1

          Retrieve the absolute source directory path var src:string = Metalsmith(__dirname).source(); [API] https://github.com/metalsmith/metalsmith#sourcepath [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L90

        method use

        use: (plugin: Metalsmith.Plugin | Metalsmith.Plugin[]) => Metalsmith;
        • Add a plugin function to the stack.

          Parameter plugin

          The plugin to add.

          Example 1

          Add 'metalsmith-markdown' to the middleware stack Metalsmith(__dirname).use(markdown()); [API] https://github.com/metalsmith/metalsmith#useplugin [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L50

        method write

        write: {
        (files: object, dir?: string, fn?: Metalsmith.Callback): void;
        (files: object, fn: Metalsmith.Callback): void;
        };
        • Write a dictionary of files to a destination dir. If no directory is provided, it will default to the destination directory.

          Parameter files

          Dictionary of files.

          Parameter dir

          Optional destination directory.

          Parameter fn

          Optional Callback function.

          Example 1

          Write a dictionary of files to a destination dir. Metalsmith(__dirname).write({fileA: "a.html"} , "C:\\OutDir"); [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L308

        • Write a dictionary of files to a destination dir. If no directory is provided, it will default to the destination directory.

          Parameter files

          Dictionary of files.

          Parameter dir

          Optional destination directory.

          Example 1

          Write a dictionary of files to a destination dir. Metalsmith(__dirname).write({fileA: "a.html"} , "C:\\OutDir"); [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L308

        method writeFile

        writeFile: (file: string, data: object) => void;
        • Write a file by path with data. If the path is not absolute, it will be resolved relative to the destination directory.

          Parameter file

          File path.

          Parameter data

          The file data.

          Example 1

          Write a file by path with data. Metalsmith(__dirname).writeFile("test.html", {contents: "File Contents"}); [Source] https://github.com/metalsmith/metalsmith/blob/v2.3.0/lib/index.js#L336

        Type Aliases

        type Callback

        type Callback = (err: Error | null, files: Files, metalsmith: Metalsmith) => void;

          type Ignore

          type Ignore = (path: string, stat: Stats) => void;

            type Plugin

            type Plugin = (files: Files, metalsmith: Metalsmith, callback: Callback) => void;
            • A Metalsmith plugin is a function that is passed the file list, the metalsmith instance, and a done callback. Calling the callback is required for asynchronous plugins, and optional for synchronous plugins.

            Package Files (1)

            Dependencies (1)

            Dev Dependencies (0)

            No dev dependencies.

            Peer Dependencies (0)

            No peer dependencies.

            Badge

            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/metalsmith.

            • Markdown
              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/metalsmith)
            • HTML
              <a href="https://www.jsdocs.io/package/@types/metalsmith"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>