metalsmith-collections-archive

1.1.2 • Public • Published

metalsmith-collections-archive NPM version Build Status Dependency Status

Generate archive metadata and directories for Metalsmith collections.

Features

  • adds archive data to metadata
  • creates archive directory combining all collections
  • creates individual archive directories for each collection
  • the above can be toggled off based on your needs
  • produces time-specific paths on your site to improve search indexing
  • plugin uses caching internally to optimise performance and not slow down your build
  • ignores files with invalid dates

Installation

$ npm install --save-dev metalsmith-collections-archive

Usage

Configure your build

import collections from 'metalsmith-collections'
import archiveCollections from 'metalsmith-collections-archive'
import layouts from 'metalsmith-layouts'

metalsmith
  .use(collections())
  .use(archiveCollections({
    layout: 'path/to/layouts/layout.html'
  }))
  .use(layouts({
    engine: 'handlebars',
    directory: 'path/to/layouts/'
  }))

Exclude archive object in metadata

metalsmith.use(archiveCollections({
  layout: 'path/to/layouts/layout.html',
  metadata: false
}))

Exclude root-level archive directories

metalsmith.use(archiveCollections({
  layout: 'path/to/layouts/layout.html',
  rootLevel: false
}))

Exclude collections archive directories

metalsmith.use(archiveCollections({
  layout: 'path/to/layouts/layout.html',
  collections: false
}))

Only include specific collections

metalsmith.use(archiveCollections({
  layout: 'path/to/layouts/layout.html',
  collections: {
    news: true
  }
}))

Exclude specific collections

metalsmith.use(archiveCollections({
  layout: 'path/to/layouts/layout.html',
  collections: {
    events: false,
    social: false
  }
}))

Example layout

<!-- layout.html -->

<article>
  {{#if children}}
    <section>
      <ul>
        {{#each children}}
          <li><a href="/{{ path }}" title="{{ title }}">{{ title }}</li>
        {{/each}}
      </ul>
    </section>
  {{/if}}
  <section>
    {{#unless children}}
      <h2>{{ title }}</h2>
    {{/unless}}
    <ul>
      {{#each posts}}
        <li><a href="/{{ path }}" title="{{ title }}">{{ title }}</li>
      {{/each}}
    </ul>
  </section>
</article>

Combine with a sitemap plugin (recommended!)

import collections from 'metalsmith-collections'
import archiveCollections from 'metalsmith-collections-archive'
import layouts from 'metalsmith-layouts'
import sitemap from 'metalsmith-mapsite'

metalsmith
  .use(collections())
  .use(archiveCollections({
    layout: 'path/to/layouts/layout.html'
  }))
  .use(layouts({
    engine: 'handlebars',
    directory: 'path/to/layouts/'
  }))
  .use(sitemap('https://example.com'))

CLI Usage

{
  "plugins": {
    "metalsmith-collections-archive": {
      "layout": "path/to/layouts/layout.html"
    }
  }
}

License

MIT License

Copyright (c) 2017 Yann Eves <hello@yanneves.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i metalsmith-collections-archive

Weekly Downloads

8

Version

1.1.2

License

MIT

Unpacked Size

41.2 kB

Total Files

239

Last publish

Collaborators

  • yanneves