front-matter
Advanced tools
Comparing version
@@ -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 @@ | ||
[](http://travis-ci.org/jxson/front-matter) [](https://coveralls.io/r/jxson/front-matter?branch=) [](https://david-dm.org/jxson/front-matter) | ||
[](http://travis-ci.org/jxson/front-matter) [](https://coveralls.io/r/jxson/front-matter?branch=master) [](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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
14773
10.08%15
15.38%140
8.53%110
2.8%0
-100%