// 响应首页的处理函数 func (i Index) Index(res web.Resource) { i.Layout = "index.html" i.LayoutData = make(map[string]interface{}) i.LayoutData["BlogTitle"] = web.Conf.Get("Blog", "name") data := make(map[string]interface{}) // 处理文章数据 data["articlelist"] = model.NewArticleModelList(nil, 6) // 处理评论数据 data["comments"] = model.NewCommentModelList("", 5) i.Render(res, data) }
// 前台文章展示 func (a Article) Show(res web.Resource) { a.Layout = "index.html" a.LayoutData = make(map[string]interface{}) a.LayoutData["BlogTitle"] = web.Conf.Get("Blog", "name") id := res.URLValue("id") if id == "" { a.Redirect(res, "/") return } article := model.NewArticleModel(id) if article == nil { a.ShowMessage(res, "您要查看的文章不存在", "/", 5) } else { data := make(map[string]interface{}) data["article"] = article data["comments"] = model.NewCommentModelList(id, 10) a.Render(res, data) } }