0.0.1 • Published 9 years ago

metalsmith-hideshow v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

metalsmith-hideshow

A metalsmith plugin to temporary hide some files from some plugins.

Example 1.

Metalsmith-feed and metalsmith-react-templates

I would like to put text to RSS before it was processed by React. But if I place React-plugin after the RSS-plugin then React also wraps rss.xml.

I can hide rss.xml by HideShow plugin, process other files by React and then show rss.xml back.

Example 2.

I would like to keep content related binaries (e.g. cover photos) in the same tree as .md files. But some plugins may damage binaries. I hide binaries in the beginning of chain and show them back in the end before final deployment.

Usage

var hideshow = require('metalsmith-hideshow');

Metalsmith(__dirname)
  .use(hideshow({
    hide: function(filename) {
      return !filename.match(/.*\.md$/);
    }
  }))

  .use(markdown())
  .use(templates('handlebars'))

  .use(hideshow({
    show:true
  }))
  .build(function(err) {
    if (err) throw err;
  });

Options

  • name string optional. The name of files storage where they are hidden or shown from it.
  • hide function(filename, fileobject) require to hide. The predicate which returns true if file should be hidden and false otherwise.
  • show boolean required to show. Should be true if you want to show files. Should be omitted if you want to hide.

Config example:

Hide files which paths are beginning with 'a' character to Default storage

{
  hide: function(name) {
    return name.charAt(0) == 'a';
  }
}

Hide files with boolean-positive draft property in Default storage

{
  hide: function(name, file) {
    return file.draft;
  }
}

Show hidden files from Default storage

{
  show: true
}

Hide files to named storage "storage_a"

{
  name: "storage_a",
  hide: function(name) {
    return name.charAt(0) == 'a';
  }
}

Show files from named storage "storage_a"

{
  name: "storage_a",
  show: true
}

License

The MIT License (MIT)

Copyright (c) 2015 Chivorotkiv chivorotkiv@omich.net

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.