Skip to content

Commit

Permalink
Append instead of in paginated filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipj committed Jan 2, 2016
1 parent 3422b36 commit c8eb303
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Metalsmith(__dirname)
| name | description |
|:-----|:------------|
|iteratee|Function called for each post (optional) |
|path|The path were the files will be outputted to. Appended with "-$NUM.html" where $NUM is the page number. So "blog/page" would for example result in the second page being rendered as `blog/page-2.html`. You can also use the placeholder ':collection' to insert the name of the collection. (optional)|
|path|The path were the files will be outputted to. Appended with "-$YEAR.html" where $YEAR is the year the posts has been grouped by. So "blog/page" would for example result in the second page being rendered as `blog/page-2015.html`, if there were any posts in 2015. You can also use the placeholder ':collection' to insert the name of the collection. (optional)|


## Templates
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function paginate (filePath, collection, fileName, files, iteratee) {
}

const posts = postsByYear[year];
const cloneName = baseName + '-' + (idx+1) + ext;
const cloneName = baseName + '-' + year + ext;

clone = _.clone(origFile, true, (value) => {
if (Buffer.isBuffer(value)) {
Expand Down
17 changes: 10 additions & 7 deletions test/pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ const should = require('should');

const pagination = require('../');

function oneYearAgo () {
const current = new Date();
return new Date(current.getFullYear() - 1, current.getMonth(), current.getDay());
function dateIn2015 () {
return new Date(2015, 6, 1);
}

function dateIn2016 (argument) {
return new Date(2016, 6, 1);
}

describe('Yearly pagination', () => {
Expand All @@ -24,7 +27,7 @@ describe('Yearly pagination', () => {

for (var i = 0; i < 10; i++) {
const name = 'content/posts/post-' + i + '.md';
const date = (i < 5) ? new Date() : oneYearAgo();
const date = (i < 5) ? dateIn2016() : dateIn2015();

files[name] = {
title: 'Post Number ' + i,
Expand Down Expand Up @@ -118,7 +121,7 @@ describe('Yearly pagination', () => {
it('pagination.next references the next paginated page', (done) => {
pagination()(files, metalsmith, () => {
const firstPage = files['blog.md'];
const secondPage = files['blog-2.md'];
const secondPage = files['blog-2015.md'];

firstPage.pagination.next.should.equal(secondPage);
done();
Expand All @@ -128,7 +131,7 @@ describe('Yearly pagination', () => {
it('pagination.prev references the previous paginated page', (done) => {
pagination()(files, metalsmith, () => {
const firstPage = files['blog.md'];
const secondPage = files['blog-2.md'];
const secondPage = files['blog-2015.md'];

secondPage.pagination.prev.should.equal(firstPage);
done();
Expand All @@ -146,7 +149,7 @@ describe('Yearly pagination', () => {

it('pagination.next is not defined for the last page', (done) => {
pagination()(files, metalsmith, () => {
const lastPage = files['blog-2.md'];
const lastPage = files['blog-2015.md'];

lastPage.pagination.should.not.have.property('next');
done();
Expand Down

0 comments on commit c8eb303

Please sign in to comment.