Skip to content

Instantly share code, notes, and snippets.

@mikevalstar
Created April 16, 2012 19:28
Show Gist options
  • Select an option

  • Save mikevalstar/2400931 to your computer and use it in GitHub Desktop.

Select an option

Save mikevalstar/2400931 to your computer and use it in GitHub Desktop.
Coding with Node.js Part 4 - section 2
// Includes
var crypto = require('crypto');
function hashString(value) {
hash = crypto.createHash('sha1');
hash.update(value);
return hash.digest('hex');
}
var AdminPages = module.exports = function AdminPages(){};
AdminPages.prototype = {
db: null
, initPages: function(app, db){
this.db = db;
var self = this;
/* ... */
// post related
app.get ('/Admin/PostList', function(req, res) { self.pagePostList(req, res); } );
/* ... */
}
/* ... */
/* Blog post related */
, pagePostList: function(req, res){ // List of blog posts
if( !this._checkLogin(req, res) ) return;
var blogpost = this.db.model('blogPost');
var query = blogpost.find().sort("posted", -1).limit(1000).exec(function(err, docs){
res.render('admin/postlist', {
title: 'Post Listing',
posts: docs,
showFullNav: false
});
});
}
};
h2 Admin - Post Listing
table.aPostList
thead
tr
th Post ID
th Title
th Int/Ext
th Posted
tbody
- posts.forEach(function(item){
tr
td= item.sid
td: a(href="/Admin/Post/" + item.sid)= item.title
td
- if(item.ext_link != ""){
| External
- }else{
| Internal
- }
td: time= item.posted
- })
a(href="/Admin/NewPost") Create a new post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment