Giter Site home page Giter Site logo

node-json-front-matter's Introduction

json-front-matter

Build Status Build Status

Extract JSON front matter from strings and files in the style of Jekyll's YAML Front Matter.

Installing

  • npm install json-front-matter

Methods

  • parse( s ) Parses string s, returning an object with properties attributes, containing the JSON front matter, and body containing the rest.
  • parseFile( path, callback( err, data )) Parses file at path, calling the callback upon completion with data object containing attributes and body, like the string parse method.

Usage

var fm = require('json-front-matter');

var string = '{{{ "title" : "some title", "array" : [ 1, 2, 3 ] }}} bodybodybody';
var out = fm.parse( string );

console.log( out.body ) // 'bodybodybody'
console.log( out.attributes.title ) // 'some title'
console.log( out.attributes.array ) // [ 1, 2, 3 ]

File Example

See ./tests/data/test.md for example of JSON Front Matter in a markdown file. The outer JSON is encapsulated via triple curly brackets. {{{ "tags" : [ 'rock', 'paper', 'scissors' ] }}}

Testing

Run node tests/runTests.js from project root -- testing uses nodeunit

License

MIT License, Copyright (c) 2012 Jordan Santell

node-json-front-matter's People

Contributors

adam-beck avatar ameyp avatar jsantell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-json-front-matter's Issues

Posts aren't updated when a new post is created or an existing one is deleted

I've added the following block of code as per the Watcher example:

poet.watch(function() {
  console.log("Poet reloaded");
}).init().then(function() {
  console.log("Ready to go!");
});

While updating the content of an existing post makes the post get updated when viewed in a browser, creating new posts or deleting existing ones doesn't work unless I close the poet instance and start a new one.

The "Poet reloaded" print appears in all three cases, i.e. update/create/delete.

Update version

The package looks pretty stable, how about updating it to v1.0.0 .. ?

I've put together a browserify transform (https://github.com/dazld/frontmatterify) that uses both this and a yaml front matter parser, and would be great to be able to reference a 'stable' release instead of the 0.x versions on npm!

Side question - what extensions do people normally use for front matter files? Is there a standardised way of referring to them..? I'm using .json.fm and .yaml.fm- for an example.

What do you think..?

promises don't appear to be behaving properly

Sorry for the rather vague title of the bug, but I'm seeing some inconsistent behaviour with promises.

Following the "Watcher" example, I have the following block of code:

poet.watch(function() {
  console.log("Poet reloaded");
}).init().then(function() {
  console.log("Ready to go!");
});

but the "Ready to go!" print never appears. If I change the code above to look like the following block:

poet.watch(function() {
  console.log("Poet reloaded");
}).init(function() {
  console.log("Ready to go!");
});

the "Ready to go!" print appears.

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.