Permalink
Browse files

Updating models and stuff. Really, quite the overhaul

  • Loading branch information...
1 parent bb6137f commit 9abb434e9570f49bdde69cb922e71be660cedaf2 @craveytrain committed Oct 13, 2013
View
@@ -1,10 +1,8 @@
# TODOs
-- syntax highlighting
- version static assets
- deploy task?
- real content/templates
...
- preprocess markdown for special tags (code, etc)
-...
-- abstract ssg to an npm module that the blog calls up
+
View
@@ -1,8 +1,7 @@
---
-title: Home
-pageSlug: home
pageType: home
---
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
View
@@ -1,6 +1,6 @@
---
title: Posts
-pageSlug: posts
pageType: list
---
+
This is the list of posts. Hi.
View
@@ -1,10 +1,9 @@
---
title: Temp Post
pageSlug: temp-post
-pageType: post
date: 2013-10-01
---
-# This is a test
+
This is a test.
# HTML
View
@@ -1,8 +0,0 @@
-'use strict';
-
-var extend = require('extend');
-
-module.exports = function(baseModel) {
- // nothing to see here
- return extend({}, baseModel);
-};
View
@@ -0,0 +1,32 @@
+'use strict';
+
+var fs = require('fs');
+var path = require('path');
+
+var modelBuilders = {};
+
+
+// go find all the model builders
+require("fs").readdirSync(__dirname).forEach(function(file) {
+ var base;
+
+ // if it's the index, exit early
+ if (file === 'index.js') return;
+
+ // get the module name
+ base = path.basename(file, path.extname(file));
+
+ // require the module onto the modelBuilders
+ modelBuilders[base] = require('./' + base);
+});
+
+module.exports = function(siteModel) {
+ var models = {};
+
+ // loop through the model builders and attach them to the models object
+ Object.keys(modelBuilders).forEach(function(pageType) {
+ models[pageType] = modelBuilders[pageType](siteModel);
+ });
+
+ return models;
+};
View
@@ -1,8 +0,0 @@
-'use strict';
-
-var extend = require('extend');
-
-module.exports = function(baseModel) {
- // nothing to see here
- return extend({}, baseModel);
-};
View
@@ -1,8 +1,18 @@
'use strict';
+var marked = require('supermarked');
var extend = require('extend');
+marked.aliases = {
+ html: 'xml'
+};
+
module.exports = function(baseModel) {
- // nothing to see here
- return extend({}, baseModel);
+ return function(data) {
+ var content = data.__content = data.__content.trim();
+
+ data.body = marked(content);
+
+ return extend({}, baseModel, data);
+ }
};
View
@@ -4,15 +4,12 @@ var marked = require('supermarked');
var excerpt = require('../lib/excerpt');
var extend = require('extend');
-marked.aliases = {
- html: 'xml'
-};
-
-module.exports = function(baseModel, data) {
- var content = data.__content.trim();
- data.excerpt = marked(data.excerpt || excerpt(content));
- data.__content = marked(content);
+module.exports = function(baseModel) {
+ return function(data) {
+ var pageModel = require('../models/page')(baseModel, data);
+ data.excerpt = marked(data.excerpt || excerpt(data.__content));
- return extend({}, baseModel, data);
+ return extend({}, pageModel, data);
+ }
};
View
@@ -1,4 +1,4 @@
-title: craveytrain
+title: Craveytrain
subtitle: I'm a little geek bot, short and stout…
author: Mike Cravey
description: The blog of Mike Cravey (@craveytrain).
@@ -5,7 +5,7 @@
@import 'third-party/normalize/normalize'
-@import 'includes/craveytrain'
+// @import 'includes/craveytrain'
@import 'third-party/highlight/syntax'
View
@@ -1,12 +1,16 @@
module.exports = function(grunt) {
'use strict';
+var path = require('path');
+var fs = require('fs');
+
var extend = require('extend');
var jsYAML = require('js-yaml');
-var path = require('path');
var yamlFront = require('yaml-front-matter');
+var modelBuilder = require('../models');
+
var siteModel = grunt.file.readYAML('site.yml');
-var baseModel = require('../models/page')(siteModel);
+var models = modelBuilder(siteModel);
function determinePageType(data, page, path) {
// if it's specified, go with it
@@ -15,25 +19,24 @@ function determinePageType(data, page, path) {
// if it's in the posts directory, it's probably a post
if (/^\/posts\//.test(path)) return 'post';
- // if it's just /, it's home dummy
- if (/^\/$/.test(path)) return 'home';
-
// otherwise, it's just a page
return 'page';
}
var buildModel = function(page, path) {
// split file contents into YAML front matter and content
var data = yamlFront.loadFront(grunt.file.read(page));
+ var modelFile;
if (!data.pageType) {
data.pageType = determinePageType(data, page, path);
}
+ modelFile = models[data.pageType] || models.page;
+
grunt.log.debug('page type:', data.pageType);
- // return the right time of model
- return require('../models/' + data.pageType)(baseModel, data);
+ return modelFile(data);
};
var buildPath = function(file) {
@@ -1,7 +1,7 @@
nav.page-nav(role='navigation')
ul
li.nav-home
- a(href='/')= title
+ a(href='/') Home
li
a(href='/posts') Posts
li
View
@@ -5,8 +5,8 @@ html.no-js(lang='en', dir='ltr')
body(id=pageSlug, class=pageType)
block header
- include includes/nav
section.main(role='main')
block content
- != __content
+ != body
+ include includes/nav
include includes/footer
View
@@ -2,4 +2,4 @@ extends layout
block content
- != __content
+ != body

0 comments on commit 9abb434

Please sign in to comment.