Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including metalsmith-basename with all npm packages installed. Try it out:

var metalsmithBasename = require("metalsmith-basename")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

metalsmith-basename v0.2.4

Add basename of the file into metadata

metalsmith-basename

A Metalsmith plugin that adds file's basename as a metadate for the file, making it available for example for permalinks and helps to generate files based on it.

npm i -D metalsmith-basename
basename({
  pattern: ['**/*.html'],
  verbose: true
})

opts.pattern (array)

Process only selected documents. Example:

basename({ 
  pattern: ['**/*', '!test-**.md'] 
})

opts.verbose (boolean)

Log the files that gets processed and skipped. Defaults to false.

Example

Example usage of plugin with others.

Installation:

npm i -D metalsmith \
  harmonize \
  gulp-load-plugins \
  metalsmith-markdown-remarkable \
  metalsmith-permalinks \
  metalsmith-basename 

Documents:

src/
  my-document.md
  my another document.md
package.json

Building:

// Harmonize is required with metalsmith when using node <= 0.12 
require('harmonize')();
var Metalsmith = require('metalsmith');
var loadPlugins = require('gulp-load-plugins');

// Using gulp plugin loader to load metalsmith plugins
var plugins = loadPlugins({
  pattern: ['metalsmith-*', 'metalsmith.*'],
  replaceString: /^metalsmith(-|\.)/,
});

new Metalsmith(__dirname)
  .use(plugins.markdownRemarkable({
    html: true
  }))
  .use(plugins.basename({
    pattern: ['**/*.html'],
    verbose: false
  }))
  .use(plugins.permalinks({
    // Using basename as output path
    pattern: ':basename'
  }))
  .build(function(err) {
    if (err) {
      console.error(err);
    }
  });

Output:

build/
  my-document/index.html
  my-another-document/index.html
src/
  my-document.md
  my another document.md
package.json

License

MIT licensed

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free