blakeembrey/metalsmith-pagination

pagination object not being read from pug template

Open

#37 opened on Apr 14, 2018

View on GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (10 forks)github user discovery
help wanted

Repository metrics

Stars
 (34 stars)
PR merge metrics
 (PR metrics pending)

Description

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.

Contributor guide