UNPKG

4.31 kBMarkdownView Raw
1# Metalsmith Paths [![version][npm-version]][npm-url] [![License][npm-license]][license-url]
2
3A Metalsmith plugin that adds file path values (`base`, `dir`, `ext`, `name`, `href`) to metadata `path` property.
4
5[![Build Status][travis-image]][travis-url]
6[![Downloads][npm-downloads]][npm-url]
7[![Code Climate][codeclimate-quality]][codeclimate-url]
8[![Coverage Status][codeclimate-coverage]][codeclimate-url]
9[![Dependency Status][dependencyci-image]][dependencyci-url]
10[![Dependencies][david-image]][david-url]
11
12## Install
13
14```bash
15npm install --production --save metalsmith-paths
16```
17
18## Usage
19
20I 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` .
21
22```js
23/*
24 * Node 7
25 */
26const paths = require('metalsmith-paths/lib/node7')
27
28/*
29 * Node 6
30 */
31const paths = require('metalsmith-paths/lib/node6')
32
33/*
34 * Node 4 (Default)
35 * Note: additional ES2015 polyfills may be required
36 */
37var paths = require('metalsmith-paths')
38```
39
40## API
41
42```js
43const metalsmith = new Metalsmith(__dirname)
44 .use(paths({
45 property: "paths"
46 }))
47```
48
49given the following directory structure:
50
51```
52src/
53└── blog
54 └── post.html
55```
56
57The following metadata will be generated:
58
59| metadata | value |
60| ------------- | ----------------- |
61| `path.base` | `post.html` |
62| `path.dir` | `blog` |
63| `path.ext` | `.html` |
64| `path.name` | `post` |
65| `path.href` | `/blog/post.html` |
66| `path.dhref` | `/blog/` |
67
68## CLI
69
70You can also use the plugin with the Metalsmith CLI by adding a key to your `metalsmith.json` file:
71
72```json
73{
74 "plugins": {
75 "metalsmith-paths": {
76 "property": "paths"
77 }
78 }
79}
80```
81
82## Options
83
84| name | description | default |
85| ---------------- | ---------------------------------- | --------- |
86| `property` | property to store the path data to | `path` |
87| `directoryIndex` | remove the filename if it matches | disabled |
88
89### directoryIndex
90
91Removes the filename from the `href` attribute if it matches the value of
92`directoryIndex`. Default: disabled. For example, the following configuration:
93
94```json
95{
96 "plugins": {
97 "metalsmith-paths": {
98 "property": "path",
99 "directoryIndex": "index.html"
100 }
101 }
102}
103```
104
105Would produce the following filenames:
106
107| Filename | path.href |
108| ----------------------------- | ----------------------------- |
109| /index.html | / |
110| /portfolio/index.html | /portfolio/ |
111| /portfolio/project1.html | /portfolio/project1.html |
112| /portfolio/project2.html | /portfolio/project2.html |
113
114
115----
116> :copyright: [ahmadnassri.com](https://www.ahmadnassri.com/)  · 
117> License: [ISC][license-url]  · 
118> Github: [@ahmadnassri](https://github.com/ahmadnassri)  · 
119> Twitter: [@ahmadnassri](https://twitter.com/ahmadnassri)
120
121[license-url]: http://choosealicense.com/licenses/isc/
122
123[travis-url]: https://travis-ci.org/ahmadnassri/metalsmith-paths
124[travis-image]: https://img.shields.io/travis/ahmadnassri/metalsmith-paths.svg?style=flat-square
125
126[npm-url]: https://www.npmjs.com/package/metalsmith-paths
127[npm-license]: https://img.shields.io/npm/l/metalsmith-paths.svg?style=flat-square
128[npm-version]: https://img.shields.io/npm/v/metalsmith-paths.svg?style=flat-square
129[npm-downloads]: https://img.shields.io/npm/dm/metalsmith-paths.svg?style=flat-square
130
131[codeclimate-url]: https://codeclimate.com/github/ahmadnassri/metalsmith-paths
132[codeclimate-quality]: https://img.shields.io/codeclimate/github/ahmadnassri/metalsmith-paths.svg?style=flat-square
133[codeclimate-coverage]: https://img.shields.io/codeclimate/coverage/github/ahmadnassri/metalsmith-paths.svg?style=flat-square
134
135[david-url]: https://david-dm.org/ahmadnassri/metalsmith-paths
136[david-image]: https://img.shields.io/david/ahmadnassri/metalsmith-paths.svg?style=flat-square
137
138[dependencyci-url]: https://dependencyci.com/github/ahmadnassri/metalsmith-paths
139[dependencyci-image]: https://dependencyci.com/github/ahmadnassri/metalsmith-paths/badge?style=flat-square