blakeembrey/metalsmith-pagination

pagination object not being read from pug template

Open

#37 aperta il 14 apr 2018

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (10 fork)github user discovery
help wanted

Metriche repository

Star
 (34 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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.

Guida contributor