Skip to content

A metalsmith plugin to add namespaced global data objects from files or dynamically from plain JS objects or functions.

License

Notifications You must be signed in to change notification settings

dronedeploy/metalsmith-data

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

metalsmith-data

A metalsmith plugin to add namespaced global data objects from files or dynamically from plain JS objects or functions.

Installation

$ npm install metalsmith-data

Usage

var metalsmith = require('Metalsmith')

metalsmith
  .use(data(
    {
      // Add data from file to the `data.test1` namespace:
      test1: './path/to/test/file.json',
  
      // Add nested property from file to the `data.test2` namespace:
      test2: {
        src: './path/to/test/file.json',
        property: 'propName'
      },

      // Add a plain JS object to the `data.test3` namespace:
      test3: {
        foo: 'bar'
      },


      // Add a plain JS object to the `data.test4` namespace, via a function:
      test4: function() {
          var bar = 1+2;
          return { foo: bar }
      },
      
      // Add options to use with a CSV file
      // See: https://csv.js.org/parse/options/
      test5: {
        src: './path/to/test/file.csv',
        options:{
          delimiter: ',', //Set the field delimiter. Defaults to ","
          columns: true, //Generate records as object literals instead of arrays
          trim: true, //ignore whitespace immediately around the delimiter
          cast: true //attempt to convert input string to native types
        }
      }
  }))

Contributing

See Contributing.

About

A metalsmith plugin to add namespaced global data objects from files or dynamically from plain JS objects or functions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%