blakeembrey / metalsmith-pagination

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

pagination object not being read from pug template #37

Open michaelkornblum opened 6 years ago

michaelkornblum commented 6 years ago

I'm trying to use the pagination object in my templates, but when I try to build out my site I get a "Cannot read property 'files' of Undefined. I'm assuming the undefined is in fact, the pagination object.

html(lang="en")
  head
    meta(charset="utf-8")
    meta(http-equiv='X-UA-Compatible', content='IE=edge,chrome=1')
    meta(name="viewport", content="width=device-width")
    title= Home
  body
    h1 Home
    each article in pagination.files
      article.content-article
        header
          span.timestamp= article.date
            h2
              a(href=`/${article.path}/`)= article.title 

If this helps, I also have my build file.

const metalsmith = require('metalsmith');
const markdown = require('metalsmith-markdown');
const highligher = require('highlighter');
const layouts = require('metalsmith-layouts');
const permalinks = require('metalsmith-permalinks');
const collections = require('metalsmith-collections');
const pagination = require('metalsmith-pagination');

metalsmith(__dirname)
  .source('./src')
  .use(collections({
    articles: {
      pattern: 'articles/**/*.md',
      sortBy: 'date',
      reverse: true,
    }
  }))
  .use(pagination({
    'collections.articles': {
      perPage: 5,
      first: 'index.html',
      path: 'page/:num/index.html',
      layout: 'index.pug',
    }
  }))
  .use(markdown({
    gfm: true,
    tables: true,
    highlight: highligher(),
  }))
  .use(permalinks())
  .use(layouts({
    engine: 'pug',
    directory: 'layouts',
  }))

  .build((err) => {
    if (err) throw err;
  });

Thank you for your time.

blakeembrey commented 6 years ago

Is it possible any other pages (not metalsmith-pagination) are using index.pug? I haven't seen this issue myself.