Coder Social home page Coder Social logo

jonschlinkert / parser-front-matter Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 1.0 52 KB

Front matter parser that uses gray-matter and bits of real panther, so you know it's good. Kind of like consolidate.js engine, accept it's not an engine, it's a parser. Works with Assemble, express.js, parser-cache, or any application with similar conventions.

License: MIT License

JavaScript 100.00%
front-matter gray-matter parser matter yaml yaml-frontmatter static-site-generator static-site markdown html

parser-front-matter's Introduction

parser-front-matter NPM version NPM monthly downloads NPM total downloads Linux Build Status

Front matter parsing middleware based on gray-matter.

Install

Install with npm:

$ npm install --save parser-front-matter

This is similar to a consolidate.js engine, but for parsing. Works with assemble, verb, generate, update, express.js, parser-cache, or any application with similar conventions.

Usage

var parser = require('parser-front-matter');

API

Parse front matter from the given string or the contents in the given file and callback next(err, file).

If an object is passed, either file.contents or file.content may be used (for gulp and assemble compatibility).

Params

  • file {String|Object}: The object or string to parse.
  • options {Object|Function}: or next callback function. Options are passed to gray-matter.
  • next {Function}: callback function.

Example

// pass a string
parser.parse('---\ntitle: foo\n---\nbar', function (err, file) {
  //=> {content: 'bar', data: {title: 'foo'}}
});

// or an object
var file = {contents: new Buffer('---\ntitle: foo\nbar')};
parser.parse(file, function(err, res) {
  //=> {content: 'bar', data: {title: 'foo'}}
});

Parse front matter from the given string or the contents in the given file. If an object is passed, either file.contents or file.content may be used (for gulp and assemble compatibility).

Params

  • file {String|Object}: The object or string to parse.
  • options {Object}: passed to gray-matter.

Example

// pass a string
var res = parser.parseSync('---\ntitle: foo\n---\nbar');

// or an object
var file = {contents: new Buffer('---\ntitle: foo\nbar')};
var res = parser.parseSync(file);
//=> {content: 'bar', data: {title: 'foo'}}

file object

Returned file objects have the following properties (no other properties are modified on the given file):

  • data: data from parsed front matter
  • content: the content string, excluding front-matter (assemble compatibility)
  • contents: the content string as a buffer, excluding front-matter
  • orig: the original content string with front-matter included

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

Commits Contributor
69 jonschlinkert
2 doowb

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on July 16, 2017.

parser-front-matter's People

Contributors

doowb avatar jonschlinkert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

doowb

parser-front-matter's Issues

"file.isDirectory is not a function" introduced in 1.6.0

After upgrading from 1.5.0 to 1.6.0 started getting the following exceptions in... well, somewhere:

Running "assemble" task
Building "page": website/en_US/**/*.hbs
Error running middleware for website/en_US/index
TypeError: file.isDirectory is not a function

Tracked it down to this module's release of 1.6.0 last night. Pinned version 1.5.0 and the error went away. Honestly not sure how to find what's calling this, but crossing my fingers you can figure out a way to fix it :-)

Trigger new Travis build to update badge

Just a minor nitpick: The latest Travis build (5 months ago) failed for Node 0.10 and 0.12 due to gray-matter using const in its code. This was fixed in gray-matter 3.0.6. The current Travis badge implies problems that no longer exist.

Latest Update Breaks Assemble v0.6.0

I have some page templates in an Assemble project that suddenly aren't reading YAML options (specifically a "layout" setting).

If I change Assemble's package.json to:

"parser-front-matter": "jonschlinkert/parser-front-matter#e34a50248e3b43a7e8afcd2bf2486344ad3781e6",

My Assemble projects builds as expected. Not sure if this is helpful here or in the Assemble project.

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.