blakeembrey / metalsmith-pagination

A Metalsmith plugin for paginating arrays and collections
MIT License
34 stars 10 forks source link

Path fields is not populated correctly with metalsmith-collection@0.9.0 #30

Closed carolineBda closed 7 years ago

carolineBda commented 7 years ago

When you upgrade metalsmith-collections from 0.7.0 to 0.9.0 then the path field in the file object listed in pagination.files become a string "articles/le-theatre-entreprise.md"

instead of being the usual object :

{ 
  root: '',
  dir: 'articles',
  base: 'le-theatre-entreprise.md',
  ext: '.md',
  name: 'lexique-satisfaction-client-W',
  href: '/articles/le-theatre-entreprise.md,
  dhref: '/articles/' 
}

My setup is :

"metalsmith": "2.3.0",
"metalsmith-collections": "0.7.0",
"metalsmith-copy": "0.3.0",
"metalsmith-layouts": "1.8.1",
"metalsmith-markdown": "0.2.1",
"metalsmith-pagination": "1.4.0",
"metalsmith-paths": "3.0.1",
"metalsmith-publish": "0.1.5",
"metalsmith-tags": "2.0.0",
"metalsmith-text-replace": "1.0.1"
blakeembrey commented 7 years ago

@carolineBda I think I understand what your issue is now. I thought you were saying that the entire object was just a string since there wasn't enough to work off of, but now it sounds like you have some other issue. I'm still honestly not sure if I'm reading it right, so having a reproduction or better before/after can save a lot of time in the future.

The path property was added in Metalsmith collections over a year ago now (see https://github.com/segmentio/metalsmith-collections/commit/8163c4e62f098ee01f3524fd171c1af929cb788b). I've used it perfectly fine in my blog (https://github.com/blakeembrey/knowledge/blob/7e449b78090035e73aa94010c6bd8f667b7ebf8b/package.json) with 0.9.0. Were you expecting something else from this plugin?

carolineBda commented 7 years ago

Yes it is the entire path object itself which is wrong when I upgrade metalsmith-collections verison

In my template

{{#each pagination.files}}
                {{log path}}

The output is :

With metalsmith-collections@0.7.0

{ root: '',
  dir: 'articles',
  base: 'lexique-satisfaction-client-P.md',
  ext: '.md',
  name: 'lexique-satisfaction-client-P',
  href: '/articles/lexique-satisfaction-client-P.md',
  dhref: '/articles/' }

With metalsmith-collections@0.9.0

articles/lexique-satisfaction-client-P.md

The only difference between the two is the version of metalsmith-collections

blakeembrey commented 7 years ago

It seems like you probably had a plugin or something that was doing that for you. If that's what you want, you can do it yourself: https://nodejs.org/api/path.html#path_path_parse_path. As far as I've ever known, path has been a string though and nothing else. Since this isn't related to this library, I'm going to close the issue. If you aren't convinced, feel free to open the issue on metalsmith-collections or post a reproducible demo I could look at.

blakeembrey commented 7 years ago

In fact, it's exactly that: https://github.com/ahmadnassri/metalsmith-paths. If you want that information, change the property as documented in their README.

carolineBda commented 7 years ago

Oh I see. Good spot! Actually it is because in their new version they override it : https://github.com/segmentio/metalsmith-collections/commit/caa1c45423c5df8e07708127ed19647b92f14b64#diff-6d186b954a58d5bb740f73d84fe39073R39

Shame :(

Thanks for your help and your reactivity