docpad-plugin-datafiles

2.3.1 • Public • Published

docpad-plugin-datafiles

Build Status npm-version

DocPad plugin for simple data files. Loads and parses JSON, YAML, JavaScript, and CoffeeScript files from src/data/ and stores the contents on config.templateData, which makes the data available as @filename (or {{filename}} or whatever) when rendering documents and layouts.

Notable features:

  • Data is cached and only updated when the source file changes
  • Intelligent support for files with spaces, hyphens, etc. in the name (e.g. file-name.json becomes @fileName.)
  • Support for absolute folder paths

Installation

docpad install datafiles

Configuration

dataPaths: An array of folders to search for data files in. Relative dataPaths are resolved from docpadConfig.srcPath, which defaults to ./src/.

camelCase: converts file names with spaces, hyphens, etc. to camelCase to enable easier usage in templates. For example foo-bar.json becomes @fooBar when true vs @['foo-bar'] when false.

alwaysReload: Default behavior is to check the mtime and only reload modified files during regeneration. When true, this check will be skipped and all files will always be reloaded. Note that DocPad only watches for changes in folders under docpadConfig.srcPath.

Config with default options in CoffeeScript:

docpadConfig = {
  plugins: {
    datafiles: 
      dataPaths: [ 'data' ],
      camelCase: true,
      alwaysReload: false
  }    
  # ...
}
module.exports = docpadConfig

Or JavaScript:

const docpadConfig = {
  plugins: {
    datafiles: {
      dataPaths: ['data'],
      camelCase: true
      alwaysReload: false
    }
  }
  // ...
};
 
module.exports = docpadConfig;

Credits

Original code was forked from docpad-plugin-data. Tests, documentation, various features, and other improvements by Nathan Friedly.

Package Sidebar

Install

npm i docpad-plugin-datafiles

Weekly Downloads

6

Version

2.3.1

License

MIT

Last publish

Collaborators

  • nfriedly