// index page
var async = require('async');

exports = module.exports = function($ctrlers) {

    var thread = $ctrlers.thread;
    var fetchThreads = function(page, limit, query, callback) {
        var cursor = threads.page(page, limit, query);
        cursor.query.populate('lz').populate('board').exec(function(err, threads) {
            callback(err, threads, cursor.pager);
        });
    }

    // PAGE: 首页
    return {
        index: function(req, res, next) {
            fetchThreads(1, 20, {}, function(err, threads, pager) {
                if (!err) {
                    res.render('index', {
                        threads: threads,
                        pager: pager
                    });
                } else {
                    next(err);
                }
            });
        },
        page: function(req, res, next) {
            if (req.params.page && !isNaN(parseInt(req.params.page), 10)) {
                var page = parseInt(req.params.page, 10);
                fetchThreads(page, 20, {}, function(err, threads, pager) {
                    if (!err) {
                        res.render('index', {
                            threads: threads,
                            pager: pager
                        });
                    } else {
                        next(err);
                    }
                });
            } else {
                next(new Error('404'));
            }
        }
    }

}
@@ -95,17 +95,17 @@
     var 
-t
+T
 hread = 
@@ -206,23 +206,22 @@
 ursor = 
-t
+T
 hread
-s
 .page(pa
@@ -1079,32 +1079,97 @@
     if (!err) %7B%0A
+                        if (threads && threads.length %3E 0) %7B%0A    
                 
@@ -1190,32 +1190,36 @@
 nder('index', %7B%0A
+    
                 
@@ -1268,32 +1268,36 @@
                 
+  
+  
 pager: pager%0A   
@@ -1309,35 +1309,150 @@
                 
-%7D);
+    %7D);%0A                        %7D else %7B%0A                            next(new Error('404'));%0A                        %7D
 %0A               

index page bugs fixed