Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: craveytrain/ssg
base: 48ca31ca78
...
head fork: craveytrain/ssg
compare: 350c0ae4f7
  • 2 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 18, 2013
@craveytrain Moves list to an index 298ca7f
Commits on Oct 23, 2013
@craveytrain Builds out list of posts 350c0ae
View
1  .jshintrc
@@ -11,7 +11,6 @@
- "boss" : true,
"eqeqeq" : true,
"forin" : true,
"immed" : true,
View
1  Gruntfile.js
@@ -155,7 +155,6 @@ grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-autoprefixer');
-grunt.loadNpmTasks('grunt-notify');
grunt.loadTasks('tasks');
grunt.registerTask('build', ['clean', 'jshint', 'copy', 'render', 'stylus', 'autoprefixer', 'uglify']);
View
0  content/posts.md → content/posts/index.md
File renamed without changes
View
29 models/list.js
@@ -0,0 +1,29 @@
+'use strict';
+
+var extend = require('extend');
+
+function postsByLatest (posts) {
+ var arr = [];
+
+ Object.keys(posts).forEach(function(slug) {
+ arr.push(posts[slug]['/']);
+ });
+
+ return arr.sort(function(a, b) {
+ return a.date - b.date;
+ });
+}
+
+module.exports = function(siteModel) {
+ // initialize the page model with the base model content
+ var pageModel = require('./page')(siteModel);
+
+ return function(data, taxonomy) {
+ // pass the view specific data into the page model
+ var baseModel = pageModel(data);
+
+ return extend({}, baseModel, data, {
+ posts: postsByLatest(taxonomy.posts)
+ });
+ };
+};
View
2  models/page.js
@@ -8,7 +8,7 @@ marked.aliases = {
};
module.exports = function(baseModel) {
- return function(data) {
+ return function(data, taxonomy) {
// trim the whitespace from the content, drop it back in the model
var content = data.__content.trim();
View
2  models/post.js
@@ -9,7 +9,7 @@ module.exports = function(siteModel) {
// initialize the page model with the base model content
var pageModel = require('./page')(siteModel);
- return function(data) {
+ return function(data, taxonomy) {
// pass the view specific data into the page model
var baseModel = pageModel(data);
View
72 tasks/render.js
@@ -11,13 +11,14 @@ var modelBuilder = require('../models');
var siteModel = grunt.file.readYAML('site.yml');
var models = modelBuilder(siteModel);
+var taxonomy = {};
-function determinePageType (data, path) {
+function determinePageType (data) {
// if it's specified, go with it
if (data.pageType) return data.pageType;
// if it's in the posts directory, it's probably a post
- if (/^\/posts\//.test(path)) return 'post';
+ if (data.pageTaxonomy[0] === 'posts') return 'post';
// otherwise, it's just a page
return 'page';
@@ -27,23 +28,26 @@ function buildModel (data) {
var modelFile = models[data.pageType] || models.page;
// build up the model and return it
- return modelFile(data);
+ return modelFile(data, taxonomy);
}
-function buildPath (file) {
+function buildPageTaxonomy (file) {
var baseName = path.basename(file, path.extname(file));
- // trim first directory and filename
- var pathName = path.dirname(file.substring(file.indexOf(path.sep)));
+ // trim filename
+ var pageTaxonomy = path.dirname(file).split(path.sep);
+
+ // trim first directory
+ pageTaxonomy.shift();
// if basename is not index then we need to create a directory
if (baseName !== 'index') {
- pathName = path.join(pathName, baseName) + path.sep;
+ pageTaxonomy.push(baseName);
}
- grunt.log.debug('path name:', pathName);
+ grunt.log.debug('page taxonomy:', pageTaxonomy);
- return pathName;
+ return pageTaxonomy;
}
function sortViews () {
@@ -57,34 +61,48 @@ function sortViews () {
grunt.file.expand(glob).forEach(function(file) {
grunt.log.debug('file:', file);
- // define path
- var path = buildPath(file);
-
// parse the file
var data = yamlFront.loadFront(grunt.file.read(file));
+ // define the taxomony
+ var pageTaxonomy = data.pageTaxonomy = buildPageTaxonomy(file);
+
// find out the page type
- var pageType = data.pageType = determinePageType(data, path);
+ var pageType = data.pageType = determinePageType(data);
grunt.log.debug('page type:', pageType);
- var view = {
- pathName: path,
- data: data
- };
-
- // rudimentary sorting
+ // rudimentary priority queue
if (pageType === 'post') {
- viewQueue.unshift(view);
+ viewQueue.unshift(data);
} else {
- viewQueue.push(view);
+ viewQueue.push(data);
}
});
});
- // process the queue
+ // process the views
processQueue(viewQueue);
}
+function populateTaxonomy (model) {
+ // set the marker
+ var currentView = taxonomy;
+
+ model.pageTaxonomy.forEach(function(dir, i) {
+ // if the directory doesn't exist
+ if (!currentView.hasOwnProperty(dir)) {
+ // if it's the last item in the array, set it to the value, otherwise empty object
+ currentView[dir] = {};
+ }
+
+ // recursively set the marker
+ currentView = currentView[dir];
+ });
+
+ // set the data to a key that will get scrubbed out in path.normalize()
+ currentView['/'] = model;
+}
+
function processQueue (queue) {
grunt.config.requires( 'render.target', 'render.templates');
var target = grunt.config('render').target;
@@ -92,9 +110,13 @@ function processQueue (queue) {
var jadeData = grunt.config('jade');
- queue.forEach(function(view) {
- var pathName = view.pathName;
- var model = buildModel(view.data);
+ queue.forEach(function(data) {
+ var model = buildModel(data, taxonomy);
+ // build out the path from the pageTaxonomy
+ // join only takes comma separated args, so we apply it to send an array
+ var pathName = model.pathname = path.normalize('/' + path.join.apply(this, model.pageTaxonomy) + '/');
+
+ populateTaxonomy(model);
// Set model data
jadeData[pathName] = {
View
2  templates/includes/nav.jade
@@ -3,7 +3,7 @@ nav.page-nav(role='navigation')
li.nav-home
a(href='/') Home
li
- a(href='/posts') Posts
+ a(href='/posts/') Posts
li
a(href='/#about') About
li
View
6 templates/list.jade
@@ -3,6 +3,6 @@ extends layout
block content
ol
- li holas
- li list
- li items
+ each post in posts
+ li
+ a(href=post.pathname)= post.title

No commit comments for this range

Something went wrong with that request. Please try again.