Giter Club home page Giter Club logo

metalsmith-paginate's Introduction

#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

metalsmith-paginate's People

Contributors

dpobel avatar misterdai avatar robinthrift avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

metalsmith-paginate's Issues

pagination.next.path not correct

I am using this pugin with the following settings:

    .use(paginate({
        perPage: 10,
        path: 'index'
    }))

The index files (in my case index.html and index-2.html) are correctly generated but pagination.next.path is always set to "index.html".

Looking at the source code this is never changed for clone object.

I have a big problem...

Your plugin doesn't work.... when i have 7 contents it doesn't work to collapse them 2 on page. What's the problem ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.