DirectoryMeta

Applies metadata from specified input documents to all input documents based on a directory hierarchy.

This module allows you to specify certain documents that contain common metadata for all other documents in the same directory (and optionally nested directories). It assumes that all input documents are generated from the file system (for example, from the Wyam.Core.Modules.IO.ReadFiles module). In other words, both the documents that contain the common metadata and the documents to which the common metadata should be applied should be passed as inputs to this module.

Documents that contain the common metadata are specified by file name using the WithMetadataFile method. You can specify more than one metadata file and/or metadata files at different levels in the directory hierarchy. If the same metadata key exists across multiple common metadata documents, the following can be used to determine which metadata value will get set in the target output documents:

  • Pre-existing metadata in the target document (common metadata will not overwrite existing metadata unless the replace flag is set).
  • Common metadata documents in the same directory as the target document (those registered first have a higher priority).
  • Common metadata documents in parent directories of the target document (but only if the inherited flag is set and those closer to the target document have a higher priority).

By default, documents that are identified as containing common metadata will be filtered and won't be contained in the sequence of output documents. PreserveMetadataFiles can be used to change this behavior.

Usage

  • DirectoryMeta()

Fluent Methods

Chain these methods together after the constructor to modify behavior.

  • WithMetadataFile(DocumentConfig metadataFileName, bool inherited = false, bool replace = false)

    Specifies a file name to use as common metadata using a delegate so that the common metadata document can be specific to the input document.

    • metadataFileName

      A delegate that returns a bool indicating if the current document contains the metadata you want to use.

    • inherited

      If set to true, metadata from documents with this file name will be inherited by documents in nested directories.

    • replace

      If set to true, metadata from this document will replace any existing metadata on the target document.

  • WithMetadataFile(FilePath metadataFileName, bool inherited = false, bool replace = false)

    Specifies a file name to use as common metadata.

    • metadataFileName

      Name of the metadata file.

    • inherited

      If set to true, metadata from documents with this file name will be inherited by documents in nested directories.

    • replace

      If set to true, metadata from this document will replace any existing metadata on the target document.

  • WithPreserveMetadataFiles()

    Preserves the files that hold the common metadata and ensures they are included in the module output. Without this option, theses documents will be consumed by this module and will not be present in the module output.

GitHub