npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

metalsmith-pagination

v1.5.0

Published

A Metalsmith plugin for paginating arrays and collections.

Downloads

1,605

Readme

Metalsmith Pagination

NPM version NPM downloads Build status Test coverage

A Metalsmith plugin for paginating arrays and collections.

Installation

npm install metalsmith-pagination --save

Usage

To paginate an array of files, you need to have a property that points to the location of the collection you want to paginate. The value should be an options object that will be used to initialize the plugin.

P.S. Make sure the pagination middleware is defined after the files array exists, but before the template middleware renders.

CLI

Install via npm and then add metalsmith-pagination to your metalsmith.json:

{
  "plugins": {
    "metalsmith-pagination": {
      "collections.articles": {
        "perPage": 5,
        "template": "index.jade",
        "first": "index.html",
        "path": "page/:num/index.html",
        "filter": "private !== true",
        "pageMetadata": {
          "title": "Archive"
        }
      }
    }
  }
}

JavaScript

Install via npm, require the module and .use the result of the function.

var pagination = require('metalsmith-pagination')

metalsmith.use(pagination({
  'collections.articles': {
    perPage: 5,
    template: 'index.jade',
    first: 'index.html',
    path: 'page/:num/index.html',
    filter: function (page) {
      return !page.private
    },
    pageMetadata: {
      title: 'Archive'
    }
  }
}))

Options

  • perPage The number of files per page (default: 10).
  • first An optional path to use in place of the page one (E.g. Render as the homepage index.html, instead of page/1/index.html).
  • path The path to render every page under. Interpolated with the pagination object, so you can use :name, :num or :index.
  • filter A string or function used to filter files in pagination.
  • pageMetadata The metadata to merge with every page.
  • noPageOne Set to true to disable rendering of page one, useful in conjunction with first (default: false).
  • groupBy Set the grouping algorithm manually (default: paginated by perPage). Useful for paginating by other factors, like year published (E.g. date.getFullYear()).
  • empty Allows empty pages for collections. This will also be used as the file passed to groupBy to get the page name.
  • template The template metadata for metalsmith-templates.
  • layout The layout metadata for metalsmith-layouts.
  • pageContents Set the contents of generated pages (default: Buffer.from('')). Useful for metalsmith-in-place (especially with pageMetadata).

Page Metadata

The pageMetadata option is optional. The object passed as pageMetadata is merged with the metadata of every page generated. This allows you to add arbitrary metadata to every page, such as a title variable.

Template Usage

Within the template you specified, you will have access to pagination specific helpers:

  • pagination.num The current page number.
  • pagination.index The current page index (num - 1).
  • pagination.getPages(num) Get an array of num pages with the current page as centered as possible
  • pagination.name The page name from groupBy. If no groupBy was used, it is the current page number as a string.
  • pagination.files All the files to render in the current page (E.g. array of x articles).
  • pagination.pages References to every page in the collection (E.g. used to render pagination numbers).
  • pagination.next The next page, if it exists.
  • pagination.previous The previous page, if it exists.
  • pagination.first The first page, equal to pagination.pages[0].
  • pagination.last The last page, equal to pagination.pages[pagination.pages.length - 1].

For example, in Jade:

block content
  each file in pagination.files
    article.content
      header.header
        small.header-metadata
          time.timestamp(datetime=file.date)= moment(file.date).format('MMMM D, YYYY')
        h2.content-title
          a(href='/' + file.path)= file.title
      section.content-article!= file.snippet
  nav.navigation.cf
    if pagination.previous
      a.btn.pull-right(href='/' + pagination.previous.path)
        | Newer  
        i.icon-right-dir
    if pagination.next
      a.btn.pull-left(href='/' + pagination.next.path)
        i.icon-left-dir
        |   Older

License

MIT