精简主页的载入

This commit is contained in:
Alsotang 2014-04-22 12:02:22 +08:00
parent 5c472d004e
commit 3fb743cf99
3 changed files with 14 additions and 55 deletions

View File

@ -24,38 +24,19 @@ exports.index = function (req, res, next) {
keyword = keyword.trim();
var limit = config.list_topic_count;
var render = function (tags, topics, hot_topics, stars, tops, no_reply_topics, pages) {
var all_tags = tags.slice(0);
// 计算最热标签
tags.sort(function (tag_a, tag_b) {
return tag_b.topic_count - tag_a.topic_count;
var proxy = EventProxy.create('topics', 'tops', 'no_reply_topics', 'pages',
function (topics, tops, no_reply_topics, pages) {
res.render('index', {
topics: topics,
current_page: page,
list_topic_count: limit,
tops: tops,
no_reply_topics: no_reply_topics,
pages: pages,
keyword: keyword
});
});
// 计算最新标签
tags.sort(function (tag_a, tag_b) {
return tag_b.create_at - tag_a.create_at;
});
var recent_tags = tags.slice(0, 5);
res.render('index', {
tags: all_tags,
topics: topics,
current_page: page,
list_topic_count: limit,
recent_tags: recent_tags,
hot_topics: hot_topics,
stars: stars,
tops: tops,
no_reply_topics: no_reply_topics,
pages: pages,
keyword: keyword
});
};
var proxy = EventProxy.create('tags', 'topics', 'hot_topics', 'stars', 'tops', 'no_reply_topics', 'pages', render);
proxy.fail(next);
// 取标签
Tag.getAllTags(proxy.done('tags'));
var options = { skip: (page - 1) * limit, limit: limit, sort: [ ['top', 'desc' ], [ 'last_reply_at', 'desc' ] ] };
var query = {};
@ -65,10 +46,6 @@ exports.index = function (req, res, next) {
}
// 取主题
Topic.getTopicsByQuery(query, options, proxy.done('topics'));
// 取热门主题
Topic.getTopicsByQuery({}, { limit: 5, sort: [ [ 'visit_count', 'desc' ] ] }, proxy.done('hot_topics'));
// 取星标用户
User.getUsersByQuery({ is_star: true }, { limit: 5 }, proxy.done('stars'));
// 取排行榜上的用户
User.getUsersByQuery({'$or': [
{is_block: {'$exists': false}},

View File

@ -69,22 +69,4 @@
</div>
<% } %>
<% if (locals.stars) { %>
<div class='panel'>
<div class='header'>
<span class='col_fade'>社区达人</span> &nbsp;
<a class='dark' href='/stars'>更多»</a>
</div>
<div class='inner'>
<% if (stars.length > 0) { %>
<ul class='unstyled'>
<%- partial('user/star', { collection: stars, as: 'user' }) %>
</ul>
<% } else { %>
<p></p>
<% } %>
</div>
</div>
<% } %>
</div>

View File

@ -12,9 +12,9 @@
<h3>关于</h3>
<hr />
<div class="topic_content">
<p>CNodeJS.org 为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。</p>
<p>CNode 社区由一批热爱Node技术的工程师发起目前已经吸引了互联网各个公司的专业技术人员加入我们非常欢迎更多对 Node 感兴趣的朋友加入我们(发邮件到 <a href='mailto:nodejs@126.com'>nodejs@126.com</a></p>
<p>cnodejs.org 为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。</p>
<p>CNode 社区由一批热爱 Node.js 技术的工程师发起,目前已经吸引了互联网各个公司的专业技术人员加入,我们非常欢迎更多对 Node.js 感兴趣的朋友。</p>
</div>
</div>
</div>
</div>
</div>