blakeembrey / metalsmith-pagination

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

If pageContents is a string, you get undefined behavior. #33

Closed DomtronVox closed 4 years ago

DomtronVox commented 7 years ago

TL;DR: When you set pageContents to a string, layouts do not get applied to the page.

Hello, I just solved an issue I was having with this plugin. It took me awhile and I had to dig through several plugins before I figured it out.

You have to pass a buffer object for the pageContents option. If you pass a string, the layout plugin fails, silently, it's utf8 check. When I ran my build, my generated pagination page only had the string I passed, no html from the layout.

I suggest doing a typeof check for strings on the pageContents option and either throw an error or create a new buffer using the string.

BTW, Thank you for creating and maintaining this plugin!

blakeembrey commented 7 years ago

I'd welcome a PR to convert strings to a buffer. I'm not sure if it's ever valid to use a string, I can't recall from memory if metalsmith works fine internally with a string but I feel like it does.

blakeembrey commented 4 years ago

Fixed with https://github.com/blakeembrey/metalsmith-pagination/commit/cbc6d6e88632c6c9e670f17484f95f523f3060a3.