Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Home model and latest post

  • Loading branch information...
commit f4fd0a30f8d119f33a2cfd4c50e22083d92298b2 1 parent aa09828
@craveytrain authored
Showing with 39 additions and 8 deletions.
  1. +17 −0 models/home.js
  2. +17 −8 models/post.js
  3. +5 −0 templates/home.jade
View
17 models/home.js
@@ -0,0 +1,17 @@
+'use strict';
+
+var extend = require('extend');
+
+var pageModel = require('./page');
+var postModel = require('./post');
+
+module.exports = {
+ buildModel: function (siteModel, data, taxonomy) {
+ // pass the site model and the view specific data into the page model
+ var baseModel = pageModel.buildModel(siteModel, data);
+
+ return extend({}, baseModel, data, {
+ post: postModel.latestPost(taxonomy.posts)
+ });
+ }
+};
View
25 models/post.js
@@ -19,6 +19,20 @@ var getPosts = (function(posts) {
};
}([]));
+function postsByLatest (taxonomyPosts) {
+ var posts = getPosts(taxonomyPosts);
+
+ return posts.sort(function(a, b) {
+ return a.date - b.date;
+ });
+}
+
+function latestPost (taxonomyPosts) {
+ var posts = postsByLatest(taxonomyPosts);
+
+ return posts[0];
+}
+
module.exports = {
buildModel: function (siteModel, data, taxonomy) {
// pass the site model and the view specific data into the page model
@@ -26,14 +40,9 @@ module.exports = {
return extend({}, baseModel, data, {
// create excerpt if non exists and mark it down
- excerpt: marked(baseModel.excerpt || excerpt(baseModel.content))
+ excerpt: baseModel.excerpt || excerpt(baseModel.content)
});
},
- postsByLatest: function (taxonomyPosts) {
- var posts = getPosts(taxonomyPosts);
-
- return posts.sort(function(a, b) {
- return a.date - b.date;
- });
- }
+ postsByLatest: postsByLatest,
+ latestPost: latestPost
};
View
5 templates/home.jade
@@ -8,6 +8,11 @@ block header
block content
+ article#latestPost
+ h2
+ a(href=post.pathname)= post.title
+ p= post.excerpt
+
article#about
h2 About
p Hi, my name is Mike Cravey and I am a geek. This is my personal echo chamber for things tech related and well, whatever else I'm comfortable throwing out into the world.
Please sign in to comment.
Something went wrong with that request. Please try again.