Files
leanote/app/controllers/PreviewController.go

104 lines
3.1 KiB
Go
Raw Normal View History

2014-11-09 16:24:19 +08:00
package controllers
import (
"github.com/revel/revel"
2015-11-13 17:58:41 +08:00
// "strings"
// "time"
2014-11-09 16:24:19 +08:00
// "encoding/json"
2015-11-13 17:58:41 +08:00
// "github.com/leanote/leanote/app/info"
// . "github.com/leanote/leanote/app/lea"
// "github.com/leanote/leanote/app/lea/blog"
// "gopkg.in/mgo.v2/bson"
2014-11-09 16:24:19 +08:00
// "github.com/leanote/leanote/app/types"
// "io/ioutil"
// "math"
// "os"
// "path"
)
type Preview struct {
Blog
}
// 得到要预览的主题绝对路径
func (c Preview) getPreviewThemeAbsolutePath(themeId string) bool {
if themeId != "" {
2015-11-28 15:17:36 +08:00
c.Session["themeId"] = themeId // 存到session中, 下次的url就不能带了, 待优化, 有时会取不到
2014-11-09 16:24:19 +08:00
} else {
themeId = c.Session["themeId"] // 直接从session中获取
}
if themeId == "" {
return false
}
theme := themeService.GetTheme(c.GetUserId(), themeId)
2015-11-13 17:58:41 +08:00
c.ViewArgs["isPreview"] = true
c.ViewArgs["themeId"] = themeId
c.ViewArgs["themeInfoPreview"] = theme.Info
c.ViewArgs["themePath"] = theme.Path
2014-11-09 16:24:19 +08:00
if theme.Path == "" {
return false
}
return true
}
func (c Preview) Index(userIdOrEmail string, themeId string) revel.Result {
if !c.getPreviewThemeAbsolutePath(themeId) {
return c.E404()
}
return c.Blog.Index(c.GetUserId())
// return blog.RenderTemplate("index.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(themeId))
2014-11-09 16:24:19 +08:00
}
func (c Preview) Tag(userIdOrEmail, tag string) revel.Result {
if !c.getPreviewThemeAbsolutePath("") {
return c.E404()
}
return c.Blog.Tag(c.GetUserId(), tag)
}
func (c Preview) Tags(userIdOrEmail string) revel.Result {
if !c.getPreviewThemeAbsolutePath("") {
return c.E404()
}
return c.Blog.Tags(c.GetUserId())
2015-11-13 17:58:41 +08:00
// if tag == "" {
// return blog.RenderTemplate("tags.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(""))
2015-11-13 17:58:41 +08:00
// }
// return blog.RenderTemplate("tag_posts.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(""))
2014-11-09 16:24:19 +08:00
}
2014-11-10 23:56:15 +08:00
func (c Preview) Archives(userIdOrEmail string, notebookId string, year, month int) revel.Result {
2014-11-09 16:24:19 +08:00
if !c.getPreviewThemeAbsolutePath("") {
return c.E404()
}
2014-11-10 23:56:15 +08:00
return c.Blog.Archives(c.GetUserId(), notebookId, year, month)
// return blog.RenderTemplate("archive.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(""))
2014-11-09 16:24:19 +08:00
}
2014-11-12 17:32:03 +08:00
func (c Preview) Cate(userIdOrEmail, notebookId string) revel.Result {
2014-11-09 16:24:19 +08:00
if !c.getPreviewThemeAbsolutePath("") {
return c.E404()
}
2014-11-12 17:32:03 +08:00
return c.Blog.Cate(userIdOrEmail, notebookId)
// return blog.RenderTemplate("cate.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(""))
2014-11-09 16:24:19 +08:00
}
2014-11-12 17:32:03 +08:00
func (c Preview) Post(userIdOrEmail, noteId string) revel.Result {
2014-11-09 16:24:19 +08:00
if !c.getPreviewThemeAbsolutePath("") {
return c.E404()
}
2014-11-12 17:32:03 +08:00
return c.Blog.Post(userIdOrEmail, noteId)
// return blog.RenderTemplate("view.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(""))
2014-11-09 16:24:19 +08:00
}
2014-11-12 17:32:03 +08:00
func (c Preview) Single(userIdOrEmail, singleId string) revel.Result {
2014-11-09 16:24:19 +08:00
if !c.getPreviewThemeAbsolutePath("") {
return c.E404()
}
2014-11-12 17:32:03 +08:00
return c.Blog.Single(userIdOrEmail, singleId)
// return blog.RenderTemplate("single.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(""))
2014-11-09 16:24:19 +08:00
}
func (c Preview) Search(userIdOrEmail, keywords string) revel.Result {
if !c.getPreviewThemeAbsolutePath("") {
return c.E404()
}
return c.Blog.Search(c.GetUserId(), keywords)
// return blog.RenderTemplate("search.html", c.ViewArgs, c.getPreviewThemeAbsolutePath(""))
2015-11-13 17:58:41 +08:00
}