front-matter
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -21,4 +21,8 @@ | ||
if (regex.test(string)) return parse(string) | ||
else return { attributes: {}, body: string } | ||
var lines = string.split(/(\r?\n)/) | ||
if (lines[0] && lines[0].match(/((= yaml =)|(---))/)) { | ||
return parse(string) | ||
} else { | ||
return { attributes: {}, body: string } | ||
} | ||
} | ||
@@ -25,0 +29,0 @@ |
@@ -11,3 +11,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jxson/front-matter", | ||
@@ -14,0 +14,0 @@ "bugs": "https://github.com/jxson/front-matter/issues", |
@@ -8,7 +8,7 @@ | ||
[![build status](https://secure.travis-ci.org/jxson/front-matter.png)](http://travis-ci.org/jxson/front-matter) [![Coverage Status](https://coveralls.io/repos/jxson/front-matter/badge.svg?branch=)](https://coveralls.io/r/jxson/front-matter?branch=) [![Dependency Status](https://david-dm.org/jxson/front-matter.png)](https://david-dm.org/jxson/front-matter) | ||
[![build status](https://secure.travis-ci.org/jxson/front-matter.png)](http://travis-ci.org/jxson/front-matter) [![Coverage Status](https://coveralls.io/repos/jxson/front-matter/badge.svg?branch=master)](https://coveralls.io/r/jxson/front-matter?branch=master) [![Dependency Status](https://david-dm.org/jxson/front-matter.png)](https://david-dm.org/jxson/front-matter) | ||
This modules does not do any IO (file loading or reading), only extracting yaml front matter from strings. | ||
This concept that was originally introduced to me through the [jeykll][jeykll] blogging system and is pretty useful where you want to be able to easily add metadata to content without the need for a database. YAML is extracted from the the top of a file between matching separators of "---" or "= yaml =". | ||
This concept that was originally introduced to me through the [jeykll][jeykll] blogging system and is pretty useful where you want to be able to easily add meta-data to content without the need for a database. YAML is extracted from the the top of a file between matching separators of "---" or "= yaml =". | ||
@@ -34,2 +34,5 @@ <!-- This is part of a long running project I have been working on where I am splitting out internals of [haiku][haiku] into to separate, more useful and shareable modules. If your in need of a static site generator [check it out][haiku]. --> | ||
**NOTE:** As of `front-matter@2.0.0` valid front matter is considered to have | ||
the starting separator on the first line. | ||
Then you can do this: | ||
@@ -36,0 +39,0 @@ |
@@ -8,3 +8,2 @@ | ||
test('var fm = require("front-matter")', function(t) { | ||
var fm = require('../') | ||
t.equal(typeof fm, 'function') | ||
@@ -103,2 +102,12 @@ t.end() | ||
test('fm(string) - no front matter, markdown with hr', function(t) { | ||
read('no-front-matter.md', function(err, data) { | ||
t.error(err, 'read should not error'); | ||
var content = fm(data); | ||
t.equal(content.body, data); | ||
t.end() | ||
}) | ||
}) | ||
test('fm.test(string) - yaml seperator', function(t) { | ||
@@ -105,0 +114,0 @@ read('yaml-seperator.md', function(err, data) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14773
15
140
110
0