WriteFiles

Writes the content of each input document to the file system.
If the metadata keys WriteFileName (which requires RelativeFileDir to be set, usually by the ReadFiles module), WriteExtension (which requires RelativeFilePath to be set, usually by the ReadFiles module) or WritePath are set on an input document, that value will be used instead of what's specified in the module. For example, if you have a bunch of Razor .cshtml files that need to be rendered to .html files but one of them should be output as a .xml file instead, define the WriteExtension metadata value in the front matter of the page.

Usage

  • WriteFiles()

    Writes the document content to disk with the same file name and relative path as the input file. This requires metadata for RelativeFilePath to be set, which is done by the ReadFiles module or can be set manually.

  • WriteFiles(DocumentConfig path)

    Uses a delegate to describe where to write the content of each document. The output of the function should be either a full path to the disk location (including file name) or a path relative to the output folder.

    • path

      A delegate that returns a Wyam.Common.IO.FilePath with the desired path.

  • WriteFiles(string extension)

    Writes the document content to disk with the specified extension with the same base file name and relative path as the input file. This requires metadata for RelativeFilePath to be set (which is done by default by the ReadFiles module).

    • extension

      The extension to use for writing the file.

Fluent Methods

Chain these methods together after the constructor to modify behavior.

  • Append(bool append = true)

    Appends content to each file instead of overwriting them.

    • append

      Appends to existing files if set to true.

  • IgnoreEmptyContent(bool ignoreEmptyContent = true)

    Ignores documents with empty content, which is the default behavior.

    • ignoreEmptyContent

      If set to true, documents with empty content will be ignored.

  • OnlyMetadata(bool onlyMetadata = true)

    Indicates that only metadata should be added to the document and a file should not actually be written to the file system. This is useful for preprocessing documents so they appear in a pipeline with the correct write metadata, while actually writing them later with a second WriteFiles module invocation. Only the following metadata values are written when this flag is turned on: WritePath, RelativeFilePath, RelativeFilePathBase, and RelativeFileDir. The Destination... metadata values are not added to the document when only setting metadata..

    • onlyMetadata

      If set to true, metadata will be added to the input document(s) without actually writing them to the file system.

  • UseWriteMetadata(bool useWriteMetadata = true)

    By default the metadata values for WritePath, WriteFileName, and WriteExtension are checked and used first, even if a delegate is specified in the constructor. This method can be used to turn off the default behavior and always rely on the delegate for obtaining the write location.

    • useWriteMetadata

      If set to false, metadata of the input document will not be used.

  • Where(DocumentConfig predicate)

    Specifies a predicate that must be satisfied for the file to be written.

    • predicate

      A predicate that returns true if the file should be written.

Metadata

The following metadata is added to each document.

  • DestinationFileBase: FilePath

    The file name without any extension. Equivalent to Path.GetFileNameWithoutExtension(DestinationFilePath).

  • DestinationFileDir: DirectoryPath

    The full absolute directory of the file. Equivalent to Path.GetDirectoryName(DestinationFilePath).

  • DestinationFileExt: string

    The extension of the file. Equivalent to Path.GetExtension(DestinationFilePath).

  • DestinationFileName: FilePath

    The full file name. Equivalent to Path.GetFileName(DestinationFilePath).

  • DestinationFilePath: FilePath

    The full absolute path (including file name) of the destination file.

  • DestinationFilePathBase: FilePath

    The full absolute path (including file name) of the destination file without the file extension.

  • RelativeFileDir: DirectoryPath

    The relative directory of the file from the Wyam output folder.

  • RelativeFilePath: FilePath

    The relative path to the file (including file name) from the Wyam output folder.

  • RelativeFilePathBase: FilePath

    The relative path to the file (including file name) from the Wyam output folder without the file extension.

GitHub