Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.
/ hoast-layout Public archive

Hoast module used to transform the content of files using layouts.

License

Notifications You must be signed in to change notification settings

hoast/hoast-layout

Repository files navigation

npm package @latest npm package @next

Travis-ci status CodeCov coverage

License agreement Open issues on GitHub

hoast-layout

Transform the content of files using layouts.

As the name suggest this is a hoast module. The module has been based of metalsmith-layouts.

Usage

Install hoast-layout using npm.

$ npm install hoast-layout

Parameters

  • directories: A string or array of string leading to the directories containing the layouts. If an array is provided it will search through the directories in the given order and use the first valid result. If no directory is given it will assume the root source directory.
    • Type: String or Array of Strings
      • Required: no
  • extension: The extension of the layout. This option can be ignored and any extension can be provided by the default layout option or the frontmatter. The format should only include the extension without any punctuation before the string, for example md instead of .md.
    • Type: String
    • Required: no
  • layouts: Path to default layout if the frontmatter of the file does not specify another layout using a field named layouts or layout.
    • Type: String or Array of strings
      • Required: no
  • wrappers: Path to optional secondary layout to wrap the file's content in after the main layout has done its job. Do note this can not be overwritten via the frontmatter.
    • Type: String or Array of strings
    • Required: no
  • options: Options given to the JSTransformer.
    • Type: Object
      • Default: {}
  • patterns: Glob patterns to match file paths with. If the engine function is set it will only give the function any files matching the pattern.
    • Type: String or Array of strings
      • Default: [ '**/*.md', '**/*.markdown' ]
  • patternOptions: Options for the glob pattern matching. See planckmatch options for more details on the pattern options.
    • Type: Object
    • Default: {}
  • patternOptions.all: This options is added to patternOptions, and determines whether all patterns need to match instead of only one.
    • Type: Boolean
    • Default: false

From 0.2.0 and up the directory option has been deprecated and is replaced by the directories option.

Example

Cli

{
  "modules": {
    "read": {},
    "hoast-layout": {
      "directory": "layouts",
      "layouts": "default.hbs",
      "wrappers": "wrapper.hbs",
      "patterns": "*.html"
    }
  }
}

Script

const Hoast = require(`hoast`);
const read = Hoast.read,
      layout = require(`hoast-layout`);

Hoast(__dirname)
  .use(read())
  .use(layout({
    directory: `layouts`
    layouts: `default.hbs`,
    wrappers: `wrapper.hbs`,
    patterns: `*.html`
  }))
  .process();

In the examples the HTML files are entered into the handlebars layout.

Troubleshooting

If you are having problems with the module please enable debugging to have a closer look.

File not valid for processing.

  • The file is not utf-8 encoded.
  • The file path does not match any of the patterns.

No valid transformer found for extension .

  • Check if the JSTransformer associated with the extension is installed.