metalsmith-scoped-attributes
A Metalsmith plugin to scope local attributes to the document.
Last updated 5 years ago by elcontraption .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metalsmith-scoped-attributes 
SYNC missed versions from official npm registry.

Metalsmith Scoped Attributes

A Metalsmith plugin to scope local attributes to the document. Like Jekyll's page attribute scope.

Installation

$ npm install metalsmith-scoped-attributes

Usage

var Metalsmith = require('metalsmith');
var scopedAttributes = require('metalsmith-scoped-attributes');

Metalsmith
    .use(scopedAttributes({
        // Optional: namespace the local scope (`page` by default):
        name: 'this'

        // Optional: exclude specific attributes like `layout`. Metalsmith internal attributes like `core` and `stat` are already excluded.
        exclude: ['layout'],
    }));

Now, if your attributes are set like so:

---
title: My Document
layout: master.html
---
Contents here.

You would use them as:

{{ this.title }}: My Document
{{ layout }}: master.html
{{ this.contents }}: Contents here.

Since this plugin changes the scope of a document's attributes, care should be taken in where it's placed in the flow of plugins. For example, if you place this plugin before metalsmith-layouts, you should be sure to exclude the layout attribute because metalsmith-layouts expects it to be at the top level.

Current Tags

  • 0.1.2                                ...           latest (5 years ago)

3 Versions

  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |