Skip to content

Commit

Permalink
permalink: false option
Browse files Browse the repository at this point in the history
- Pass permalinks: false to a file to be ignored by the permalinks plugin
  • Loading branch information
rahulkgupta committed Aug 28, 2014
1 parent b995157 commit 2348134
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ metalsmith.use(permalinks({
date: 'YYYY'
}));
```

It uses [moment.js](http://momentjs.com/docs/#/displaying/format/) to format the string.

#### Relative Files
Expand Down Expand Up @@ -65,6 +65,21 @@ metalsmith.use(permalinks({
css/
style.css

#### Skipping Permalinks for a file

A file can be ignored by the metalsmith-permalinks plugin if you pass the `permalink: false` option to the yaml metadata of a file.
This is useful for hosting a static site on AWS S3, where there is a top level `error.html` file and not an `error/index.html` file.

For example, in your error.md file:

```js
---
template: error.html
title: error
permalink: false
---
```

#### CLI

You can also use the plugin with the Metalsmith CLI by adding a key to your `metalsmith.json` file:
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function plugin(options){
debug('checking file: %s', file);
if (!html(file)) return;
var data = files[file];
if (data['permalink'] === false) return;
var path = replace(pattern, data, options) || resolve(file);
var fam = family(file, files);

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/backslashes/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index
1 change: 1 addition & 0 deletions test/fixtures/backslashes/build/posts/post/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
post
1 change: 1 addition & 0 deletions test/fixtures/false-permalink/build/test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions test/fixtures/false-permalink/expected/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
5 changes: 5 additions & 0 deletions test/fixtures/false-permalink/src/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
permalink: false
title: test
---
test
Empty file.
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions test/fixtures/permalinks-ignore/src/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
permalinks-ignore: true
title: test
---

test
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ describe('metalsmith-permalinks', function(){
});

});

it('should ignore any files with permalink equal to false option', function(done){
Metalsmith('test/fixtures/false-permalink')
.use(permalinks(':title'))
.build(function(err){
if (err) return done(err);
equal('test/fixtures/false-permalink/expected', 'test/fixtures/false-permalink/build');
done();
});
});
});

0 comments on commit 2348134

Please sign in to comment.