metalsmith / collections

A Metalsmith plugin that groups files together into collections, which it adds to the global metadata.
MIT License
105 stars 66 forks source link

Can't get prev or next links #65

Closed abhijeetvramgir closed 2 years ago

abhijeetvramgir commented 8 years ago

I have to md files:


---
title: English
collection: articles
layout: article.hbs

---

---
title: Hindi
collection: articles
layout: article.hbs

---

I'm matching using the collection metadata. How do I get the links for the pages?? Thanks!

webketje commented 2 years ago

This can easily be done (for example with Handlebars) as:

{{ htmlifyPath article.previous.path }}

where htmlifyPath is a custom Handlebars helper. If you use'd collections before eg layouts plugin, the file metadata path will contain the template language extension and you need to replace the extension with, eg .html (as the helper above does, or see below)

See for example the custom plugin below, between collections & layouts

Metalsmith(__dirname)
  .use(collections())
  .use((files) => {
     Object.entries(files).forEach(([file, path]) => {
       file.path = path.replace(/\.hbs$/, '.html')
     })
  })
  .use(layouts())