A metalsmith plugin that adds file path values to metadata.

Usage no npm install needed!

<script type="module">
  import metalsmithPaths from '';


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


npm install --production --save metalsmith-paths


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')


const metalsmith = new Metalsmith(__dirname)
    property: "paths"

given the following directory structure:

└── blog
    └── post.html

The following metadata will be generated:

metadata value
path.base post.html
path.dir blog
path.ext .html post
path.href /blog/post.html
path.dhref /blog/


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

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


name description default
property property to store the path data to path
directoryIndex remove the filename if it matches disabled


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:

Filename path.href
/index.html /
/portfolio/index.html /portfolio/
/portfolio/project1.html /portfolio/project1.html
/portfolio/project2.html /portfolio/project2.html

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