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 🙏

© 2024 – Pkg Stats / Ryan Hefner

metalsmith-paginate

v0.3.0

Published

A simple plugin that uses metalsmith-collections to create a paginated collection

Downloads

40

Readme

#metalsmith-paginate

This plug-in makes metalsmith-collections "paginatable". it does so by creating virtual files which contain the information about the collection as well as the previous and next page.

You must use this in conjunction with metalsmith-collections!

##Usage

Firstly you must create a file that contains the information over which collection you want to paginate and the template name:

blog.md

---
template: TEMPLATE-NAME.EXT
paginate: posts
---

Note: if you give the page a title and use the metalsmith-permalinks plug-in you might get some weird result.

Then use your collections as usual and call paginate().


var Metalsmith  = require('metalsmith'),
    collections = require('metalsmith-collections'),
    paginate    = require('metalsmith-paginate'),
    // ...

Metalsmith(__dirname)
    .use(collections({
        posts: {
            pattern: 'content/posts/*.md',
            sortBy: 'date',
            reverse: true
        }
    }))
    .use(paginate({
        perPage: 10,
        path: "blog/page"
    }))
    .use(templates('ENGINE-NAME'))
    // ...
    .build()

##Options | name | description | |:-----|:------------| |perPage|The number of items to be displayed per page| |path|The path were the files will be outputted to. Appended with "-$NUM.html" where $NUM is the page number. So "blog/page" would for example result in the second page being rendered as blog/page-2.html. You can also use the placeholder ':collection' to insert the name of the collection.|

##Templates

The pagination info won't be of any use to you if you don't render it. Each (virtual) pagination file will contain a new object under the key "pagination" which contains the following info:

| name | description | |:-----|:------------| |num|The page number| |total|The total number of pages| |start|The start index| |end|The end index| |prev|The previous page object| |next|The next page object|

You can then use this info in your template. Here's an example using Handlebars with a custom limit helper (which can be found here).

{{#each (limit collections.posts this.pagination.end this.pagination.start)}}
    <li class="post">
        <h2 class="entry-title">
            <a href="{{ this.path }}" rel="bookmark">{{ this.title }}</a>
        </h2>
        <article class="entry-summary">
            {{{ this.excerpt }}}
        </article>
        <footer>

            <a href="{{ this.path }}" class="button">Read More</a>
        </footer>
    </li>
{{/each}}

{{#if this.pagination}}
    <nav class="pagination">
        {{#if this.pagination.next}}
            <a href="{{this.pagination.next.path}}">&lt; Prev</a>
        {{/if}}
    
        {{#if this.pagination.prev}}
            <a href="{{this.pagination.prev.path}}">Next &gt;</a>
        {{/if}}
    </nav>
{{/if}}

Note: This example also uses the metalsmith-permalinks plug-in