Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving to yaml-front-matter vs home rolled

  • Loading branch information...
commit 2e75b9ec787130fe6b6a4bdf216008975f222d88 1 parent c0ac218
@craveytrain authored
View
4 Gruntfile.js
@@ -21,7 +21,7 @@ grunt.initConfig({
render: {
content: ['content/**/*.md'],
target: 'build',
- templates: 'templates',
+ templates: 'templates'
},
jade: {
@@ -101,7 +101,7 @@ grunt.initConfig({
jshintrc: '.jshintrc'
},
grunt: ['Gruntfile.js', 'lib/**/*.js', 'tasks/**/*.js'],
- site: ['source/**/*.js']
+ site: ['source/**/*.js', 'model/**/*.js']
},
View
3  content/posts.md
@@ -2,4 +2,5 @@
title: Posts
pageSlug: posts
pageType: list
----
+---
+This is the list of posts. Hi.
View
4 models/home.js
@@ -1,6 +1,8 @@
+'use strict';
+
var extend = require('extend');
module.exports = function(baseModel) {
// nothing to see here
return extend({}, baseModel);
-}
+};
View
4 models/list.js
@@ -1,6 +1,8 @@
+'use strict';
+
var extend = require('extend');
module.exports = function(baseModel) {
// nothing to see here
return extend({}, baseModel);
-}
+};
View
4 models/page.js
@@ -1,6 +1,8 @@
+'use strict';
+
var extend = require('extend');
module.exports = function(baseModel) {
// nothing to see here
return extend({}, baseModel);
-}
+};
View
14 models/post.js
@@ -1,3 +1,5 @@
+'use strict';
+
var marked = require('marked');
var excerpt = require('../lib/excerpt');
var extend = require('extend');
@@ -6,18 +8,14 @@ marked.setOptions({
gfm: true,
pedantic: false,
sanitize: true
- // callback for code highlighter
- // highlight: function(code, lang) {
- // return hl(code);
- // }
});
module.exports = function(baseModel, data) {
- var body = data.body.trim();
- data.excerpt = marked(data.excerpt || excerpt(data.body));
+ var content = data.__content.trim();
+ data.excerpt = marked(data.excerpt || excerpt(content));
- data.body = marked(body);
+ data.__content = marked(content);
return extend({}, baseModel, data);
-}
+};
View
3  package.json
@@ -32,7 +32,8 @@
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-htmlmin": "~0.1.3",
- "grunt-contrib-stylus": "~0.8.0"
+ "grunt-contrib-stylus": "~0.8.0",
+ "yaml-front-matter": "~2.1.0"
},
"devDependencies": {
"highlight": "~0.2.3"
View
5 site.yml
@@ -6,4 +6,7 @@ rss: /atom.xml
stylesheet: /css/default.css
script: /js/main.min.js
domain: craveytrain.com
-keywords: engineering, development, user interface
+keywords:
+ - engineering
+ - development
+ - user interface
View
13 tasks/render.js
@@ -4,8 +4,7 @@ module.exports = function(grunt) {
var extend = require('extend');
var jsYAML = require('js-yaml');
var path = require('path');
-var reYAMLFM = /^\-{3}([\w\W]+)\-{3}([\w\W]*)/;
-
+var yamlFront = require('yaml-front-matter');
var siteModel = grunt.file.readYAML('site.yml');
var baseModel = require('../models/page')(siteModel);
@@ -24,14 +23,8 @@ function determinePageType(data, page, path) {
}
var buildModel = function(page, path) {
- // split file contents into frontmatter and non
- var fileContents = reYAMLFM.exec(grunt.file.read(page));
-
- // parse out YAML
- var data = jsYAML.load(fileContents[1]);
-
- // body is the rest of the file
- data.body = fileContents[2];
+ // split file contents into YAML front matter and content
+ var data = yamlFront.loadFront(grunt.file.read(page));
if (!data.pageType) {
data.pageType = determinePageType(data, page, path);
View
2  templates/home.jade
@@ -4,7 +4,7 @@ block header
header.page-header(role='banner')
hgroup
h1= title
- h2=subtitle
+ h2= subtitle
block content
View
2  templates/layout.jade
@@ -8,5 +8,5 @@ html.no-js(lang='en', dir='ltr')
include includes/nav
section.main(role='main')
block content
- != body
+ != __content
include includes/footer
View
2  templates/post.jade
@@ -2,4 +2,4 @@ extends layout
block content
- != body
+ != __content
Please sign in to comment.
Something went wrong with that request. Please try again.