blakeembrey / metalsmith-pagination

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

Docs, Using in-place templates #7

Closed ninjasort closed 9 years ago

ninjasort commented 9 years ago

Are there docs anywhere for the params on this plugin? I'm not sure what the first parameter does.

Also, how does the template get rendered? I'm using metalsmith-in-place and I'd like to choose a template from the src dir instead of the root templates or layouts.

Thanks.

blakeembrey commented 9 years ago

I'll improve the documentation, the first option allows you to specify a first page override (E.g. using index.html for the root and /page/:num every page after). The templating is purely relying on subsequent plugins have enough information to render based on metadata. For metalsmith-in-place to work, I think there needs to be a special case - I can add an option for contents and you can specify it.

blakeembrey commented 9 years ago

@cameronjroe Please let me know if the contents option would enable metalsmith-in-place. From what I quickly read, it looks like the best solution.

ninjasort commented 9 years ago

Cool, thanks for the prompt response. I was initially thinking I would be able to specify the path to the template and depending on whether it was in src or templates it would render from there. Since I have both the in-place and layouts plugins running, I'd like to handle my looping of posts in the src/blog/index.html rendered with a layout outside of src.

blakeembrey commented 9 years ago

Added the pageContents option with v1.2.0

ninjasort commented 9 years ago

Thanks for adding this. How does this work with metalsmith-in-place? Wouldn't there be a way to simply render the contents of the first page?

blakeembrey commented 9 years ago

Rendering is best left to the other plugins. With this, it'll set the contents of the file as if it was read from the filesystem and metalsmith-in-place should "Just Work".

ninjasort commented 9 years ago

So if I set pageContents: fs.readFileSync('src/writing/index.html') it works, however it's not utilizing yaml front-matter.

blakeembrey commented 9 years ago

No, it won't be using front-matter - it's purely the contents. For the front-matter, it's pageMetadata you want to set manually. That gets merged with every page.

ninjasort commented 9 years ago

Okay, got it working. Thanks.

ninjasort commented 9 years ago

Hey again. Sorry but this plugin is really challenging me. I'm not getting the path from the the pagination.files. Any idea why this might be happening?

blakeembrey commented 9 years ago

pagination.files is just the raw files. Where are the files coming from?

ninjasort commented 9 years ago

I have a collection of posts:

posts: {
      pattern: 'writing/**/*.md',
      sortBy: 'date',
      reverse: true
    }

And have set the pagination:

'collections.posts': {
      perPage: 10,
      first: 'writing/index.html',
      path: 'writing/:num/index.html',
      pageMetatdata: {
        title: 'Writing',
        permalink: 'writing'
      },
      pageContents: fs.readFileSync('src/writing/index.html'),
      layout: 'blog.liquid'
    }
blakeembrey commented 9 years ago

Here's an example from my own blog: https://github.com/blakeembrey/blakeembrey.com/blob/master/templates/index.jade. I haven't been using Metalsmith 2, but I didn't think that API changed?