lib/index.js
function extractFrontmatter(file, filePath, options, grayMatterOptions){
  if (utf8(file.contents)) {
    var parsed;

    try {
      parsed = matter(file.contents.toString(), grayMatterOptions);
    } catch (e) {
      var errMsg = 'Invalid frontmatter in file';
      if (filePath !== undefined) errMsg += ": " + filePath;
      var err = new Error(errMsg);
      err.code = 'invalid_frontmatter';
      err.cause = e;
      throw err;
    }

    if (options.hasOwnProperty('namespace')){
      var nsData = {}; nsData[options.namespace] = parsed.data;
      Object.assign(file, nsData);
    } else {
      Object.assign(file, parsed.data);
    }
    file.contents = new Buffer(parsed.content);
  }
}
function extractFrontmatter(file, filePath, options, grayMatterOptions){
  if (utf8(file.contents)) {
    var parsed;

    try {
      parsed = matter(file.contents.toString(), grayMatterOptions);
    } catch (e) {
      var errMsg = 'Invalid frontmatter in file';
      if (filePath !== undefined) errMsg += ": " + filePath;
      var err = new Error(errMsg);
      err.code = 'invalid_frontmatter';
      err.cause = e;
      throw err;
    }

    if (options.hasOwnProperty('namespace')){
      var nsData = {}; nsData[options.namespace] = parsed.data;
      Object.assign(file, nsData);
    } else {
      Object.assign(file, parsed.data);
    }
    file.contents = new Buffer(parsed.content);
  }
}
function extractFrontmatter ( file , filePath , options , grayMatterOptions ) { if ( utf8 ( file . contents ) ) { var parsed ; try { parsed = matter ( file . contents . toString ( ) , grayMatterOptions ) ; } catch ( e ) { var errMsg = 'Invalid frontmatter in file' ; if ( filePath !== undefined ) errMsg += ": " + filePath ; var err = new Error ( errMsg ) ; err . code = 'invalid_frontmatter' ; err . cause = e ; throw err ; } if ( options . hasOwnProperty ( 'namespace' ) ) { var nsData = { } ; nsData [ options . namespace ] = parsed . data ; Object . assign ( file , nsData ) ; } else { Object . assign ( file , parsed . data ) ; } file . contents = new Buffer ( parsed . content ) ; } }
Assign metadata in `file` based on the YAML frontmatter in `file.contents`.

@param {Object} file The Metalsmith file object to extract frontmatter from
@param {string} filePath The path to the file represented by `file`
@param {Object} options Options for the extraction routine
@param {Object} grayMatterOptions Options for gray-matter
Assign metadata in file based on the YAML frontmatter in file . contents .