Permalink
Browse files

Detect YAML front matter on any file, regardless of if it is .md or w…

…ithin `_posts`.

This allows proper metadata detection of YAML front matter on jekyll pages, as well as non-markdown files such as having YAML front matter on an HTML template.

Adds function _hasMetadata to utils, and uses the same YAML frontmater regex to detect'
  • Loading branch information...
1 parent 827f3c7 commit cac8038a7c56250e4362a3e6864f627eac8899dd @benbalter benbalter committed Dec 8, 2012
Showing with 7 additions and 2 deletions.
  1. +2 −2 _includes/model.js
  2. +5 −0 _includes/util.js
View
@@ -422,7 +422,7 @@ function loadPost(user, repo, branch, path, file, cb) {
return !!(app.state.permissions && app.state.permissions.push);
}
- if (!_.jekyll(path, file)) return {
+ if (!_.hasMetadata(content)) return {
raw_metadata: "",
content: content,
published: false,
@@ -442,7 +442,7 @@ function loadPost(user, repo, branch, path, file, cb) {
cb(err, _.extend(post, {
"sha": commit,
"markdown": _.markdown(file),
- "jekyll": _.jekyll(path, file),
+ "jekyll": _.hasMetadata(data),
"repo": repo,
"path": path,
"file": file,
View
@@ -83,6 +83,11 @@ _.jekyll = function(path, file) {
return !!(path.match('_posts') && _.markdown(file));
};
+// check if a given file has YAML frontmater
+// -------
+_.hasMetadata = function(content) {
+ return content.match( /^(---\n)((.|\n)*?)\n---\n?/ );
+}
// Extract file extension
// -------

0 comments on commit cac8038

Please sign in to comment.