{"id":15650856,"url":"https://github.com/blakeembrey/metalsmith-pagination","last_synced_at":"2025-07-26T19:05:12.783Z","repository":{"id":23154801,"uuid":"26510270","full_name":"blakeembrey/metalsmith-pagination","owner":"blakeembrey","description":"A Metalsmith plugin for paginating arrays and collections","archived":false,"fork":false,"pushed_at":"2023-12-12T07:07:24.000Z","size":358,"stargazers_count":34,"open_issues_count":4,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-19T08:01:38.969Z","etag":null,"topics":["javascript","metalsmith","metalsmith-pagination","paginating"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blakeembrey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-11T23:39:07.000Z","updated_at":"2023-03-28T18:28:57.000Z","dependencies_parsed_at":"2024-06-18T17:02:45.466Z","dependency_job_id":"2e931146-d6d2-46b0-9a12-34b414192913","html_url":"https://github.com/blakeembrey/metalsmith-pagination","commit_stats":{"total_commits":55,"total_committers":6,"mean_commits":9.166666666666666,"dds":0.3090909090909091,"last_synced_commit":"44cf09ede20d4ea56351378b9e880de412a8a7d5"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/blakeembrey/metalsmith-pagination","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fmetalsmith-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fmetalsmith-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fmetalsmith-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fmetalsmith-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blakeembrey","download_url":"https://codeload.github.com/blakeembrey/metalsmith-pagination/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blakeembrey%2Fmetalsmith-pagination/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267213462,"owners_count":24053912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","metalsmith","metalsmith-pagination","paginating"],"created_at":"2024-10-03T12:36:05.556Z","updated_at":"2025-07-26T19:05:12.744Z","avatar_url":"https://github.com/blakeembrey.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Metalsmith Pagination\n\n[![NPM version][npm-image]][npm-url]\n[![NPM downloads][downloads-image]][downloads-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n\nA [Metalsmith](http://metalsmith.io/) plugin for paginating arrays and [collections](https://github.com/segmentio/metalsmith-collections).\n\n## Installation\n\n```\nnpm install metalsmith-pagination --save\n```\n\n## Usage\n\nTo 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.\n\n**P.S.** Make sure the pagination middleware is defined _after_ the files array exists, but _before_ the template middleware renders.\n\n### CLI\n\nInstall via npm and then add `metalsmith-pagination` to your `metalsmith.json`:\n\n```json\n{\n  \"plugins\": {\n    \"metalsmith-pagination\": {\n      \"collections.articles\": {\n        \"perPage\": 5,\n        \"template\": \"index.jade\",\n        \"first\": \"index.html\",\n        \"path\": \"page/:num/index.html\",\n        \"filter\": \"private !== true\",\n        \"pageMetadata\": {\n          \"title\": \"Archive\"\n        }\n      }\n    }\n  }\n}\n```\n\n### JavaScript\n\nInstall via npm, require the module and `.use` the result of the function.\n\n```js\nvar pagination = require('metalsmith-pagination')\n\nmetalsmith.use(pagination({\n  'collections.articles': {\n    perPage: 5,\n    template: 'index.jade',\n    first: 'index.html',\n    path: 'page/:num/index.html',\n    filter: function (page) {\n      return !page.private\n    },\n    pageMetadata: {\n      title: 'Archive'\n    }\n  }\n}))\n```\n\n### Options\n\n* **perPage** The number of files per page (default: `10`).\n* **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`).\n* **path** The path to render every page under. Interpolated with the `pagination` object, so you can use `:name`, `:num` or `:index`.\n* **filter** A string or function used to filter files in pagination.\n* **pageMetadata** The metadata to merge with every page.\n* **noPageOne** Set to true to disable rendering of page one, useful in conjunction with first (default: `false`).\n* **groupBy** Set the grouping algorithm manually (default: paginated by `perPage`). Useful for paginating by other factors, like year published (E.g. `date.getFullYear()`).\n* **empty** Allows empty pages for collections. This will also be used as the `file` passed to `groupBy` to get the page name.\n* **template** The template metadata for [metalsmith-templates](https://npmjs.org/package/metalsmith-templates).\n* **layout** The layout metadata for [metalsmith-layouts](https://npmjs.org/package/metalsmith-layouts).\n* **pageContents** Set the contents of generated pages (default: `Buffer.from('')`). Useful for [metalsmith-in-place](https://npmjs.org/package/metalsmith-in-place) (especially with `pageMetadata`).\n\n### Page Metadata\n\nThe `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.\n\n### Template Usage\n\nWithin the template you specified, you will have access to pagination specific helpers:\n\n* **pagination.num** The current page number.\n* **pagination.index** The current page index (`num - 1`).\n* **pagination.getPages(num)** Get an array of `num` pages with the current page as centered as possible\n* **pagination.name** The page name from `groupBy`. If no `groupBy` was used, it is the current page number as a string.\n* **pagination.files** All the files to render in the current page (E.g. array of `x` articles).\n* **pagination.pages** References to every page in the collection (E.g. used to render pagination numbers).\n* **pagination.next** The next page, if it exists.\n* **pagination.previous** The previous page, if it exists.\n* **pagination.first** The first page, equal to `pagination.pages[0]`.\n* **pagination.last** The last page, equal to `pagination.pages[pagination.pages.length - 1]`.\n\nFor example, in Jade:\n\n```jade\nblock content\n  each file in pagination.files\n    article.content\n      header.header\n        small.header-metadata\n          time.timestamp(datetime=file.date)= moment(file.date).format('MMMM D, YYYY')\n        h2.content-title\n          a(href='/' + file.path)= file.title\n      section.content-article!= file.snippet\n  nav.navigation.cf\n    if pagination.previous\n      a.btn.pull-right(href='/' + pagination.previous.path)\n        | Newer\u0026nbsp;\u0026nbsp;\n        i.icon-right-dir\n    if pagination.next\n      a.btn.pull-left(href='/' + pagination.next.path)\n        i.icon-left-dir\n        | \u0026nbsp;\u0026nbsp;Older\n```\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/metalsmith-pagination.svg?style=flat\n[npm-url]: https://npmjs.org/package/metalsmith-pagination\n[downloads-image]: https://img.shields.io/npm/dm/metalsmith-pagination.svg?style=flat\n[downloads-url]: https://npmjs.org/package/metalsmith-pagination\n[travis-image]: https://img.shields.io/travis/blakeembrey/metalsmith-pagination.svg?style=flat\n[travis-url]: https://travis-ci.org/blakeembrey/metalsmith-pagination\n[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/metalsmith-pagination.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/blakeembrey/metalsmith-pagination?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakeembrey%2Fmetalsmith-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblakeembrey%2Fmetalsmith-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblakeembrey%2Fmetalsmith-pagination/lists"}