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 400,000 packages pre-installed, including metalsmith-paths with all npm packages installed. Try it out:

var metalsmithPaths = require("metalsmith-paths")

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

metalsmith-paths v3.0.1

A metalsmith plugin that adds file path values to metadata.

Metalsmith Paths version License

A Metalsmith plugin that adds file path values (base, dir, ext, name, href) to metadata path property.

Build Status Downloads Code Climate Coverage Status Dependency Status Dependencies

Install

npm install --production --save metalsmith-paths

Usage

I recommend using an optimized build matching your Node.js environment version, otherwise, the standard require would work just fine with any version of Node >= v4.0 .

/*
 * Node 7
 */
const paths = require('metalsmith-paths/lib/node7')

/*
 * Node 6
 */
const paths = require('metalsmith-paths/lib/node6')

/*
 * Node 4 (Default)
 * Note: additional ES2015 polyfills may be required
 */
var paths = require('metalsmith-paths')

API

const metalsmith = new Metalsmith(__dirname)
  .use(paths({
    property: "paths"
  }))

given the following directory structure:

src/
└── blog
    └── post.html

The following metadata will be generated:

metadatavalue
path.basepost.html
path.dirblog
path.ext.html
path.namepost
path.href/blog/post.html
path.dhref/blog/

CLI

You can also use the plugin with the Metalsmith CLI by adding a key to your metalsmith.json file:

{
  "plugins": {
    "metalsmith-paths": {
      "property": "paths"
    }
  }
}

Options

namedescriptiondefault
propertyproperty to store the path data topath
directoryIndexremove the filename if it matchesdisabled

directoryIndex

Removes the filename from the href attribute if it matches the value of directoryIndex. Default: disabled. For example, the following configuration:

{
  "plugins": {
    "metalsmith-paths": {
      "property": "path",
      "directoryIndex": "index.html"
    }
  }
}

Would produce the following filenames:

Filenamepath.href
/index.html/
/portfolio/index.html/portfolio/
/portfolio/project1.html/portfolio/project1.html
/portfolio/project2.html/portfolio/project2.html

:copyright: ahmadnassri.com  ·  License: ISC  ·  Github: @ahmadnassri  ·  Twitter: @ahmadnassri

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