Page 135 - Node.js开发指南
P. 135
128 第 5 章 使用 Node.js 进行 Web 开发
posts = [];
}
res.render('index', {
title: '首页',
posts: posts,
});
});
});
它的功能是读取所有用户的微博,传递给页面 posts 属性。接下来修改首页的模板
index.ejs:
<% if (!user) { %>
<div class="hero-unit">
<h1>欢迎来到 Microblog</h1>
<p>Microblog 是一个基于 Node.js 的微博系统。</p>
<p>
<a class="btn btn-primary btn-large" href="/login">登录</a>
<a class="btn btn-large" href="/reg">立即注册</a>
</p>
</div>
<% } else { %>
<%- partial('say') %>
<% } %>
<%- partial('posts') %>
下面看看首页的效果吧,图5-15和图5-16是用户登入之前和登入以后看到的首页效果。
图5-15 登入之前的首页