From 5583b4dabdac679912577d2bbd23484b17303b34 Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Sat, 7 Nov 2015 23:45:36 +0800 Subject: [PATCH] Fix post list console --- lib/plugins/console/list/post.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/plugins/console/list/post.js b/lib/plugins/console/list/post.js index 4224612350..cae4e10678 100644 --- a/lib/plugins/console/list/post.js +++ b/lib/plugins/console/list/post.js @@ -4,17 +4,25 @@ var chalk = require('chalk'); var table = require('text-table'); var common = require('./common'); +function mapName(item) { + return item.name; +} + function listPost() { var Post = this.model('Post'); var data = Post.sort({published: -1, date: 1}).map(function(post) { var date = post.published ? post.date.format('YYYY-MM-DD') : 'Draft'; - var tags = post.tags.map(function(tag) { - return tag.name; - }); - - var categories = post.categories.findOne({}).name; - return [chalk.gray(date), post.title, chalk.magenta(post.source), categories, tags.join(', ')]; + var tags = post.tags.map(mapName); + var categories = post.categories.map(mapName); + + return [ + chalk.gray(date), + post.title, + chalk.magenta(post.source), + categories.join(', '), + tags.join(', ') + ]; }); // Table header