Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permalink: false option #19

Merged
merged 1 commit into from
Sep 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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();
});
});
});