Beispiel #1
0
func manageBlogHandler(res *wcg.Response, req *wcg.Request) {
	blog, posts, err := fetchBlogForUpdate(res, req, true)
	if err != nil {
		return
	}
	res.SetLocal("blog", blog)
	res.SetLocal("posts", posts)
	res.SetLocal("js", "/static/js/admin/blog.js")
	res.Templates("admin/blog.html", "header.html", "footer.html")
}
Beispiel #2
0
func showBlogHandler(res *wcg.Response, req *wcg.Request) {
	blog, posts, err := fetchBlog(res, req, true)
	if err != nil {
		return
	}
	res.SetLocal("Og", &supports.Og{Title: blog.Title,
		Type: "blog", Url: wcg.AbsoluteUrl(req, req.URL().Path),
		Description: blog.Description, SiteName: AppConfig.SiteTitle,
	})
	res.SetLocal("blog", blog)
	res.SetLocal("is_owner", blog.OwnerId == req.User.Id())
	res.SetLocal("posts", posts)
	res.SetLocal("js", "/static/js/blog.js")
	res.Templates("blog.html", "header.html", "footer.html", "parts/post_part.html")
}
Beispiel #3
0
func editPostHandler(res *wcg.Response, req *wcg.Request) {
	blog, _, err := fetchBlogForUpdate(res, req, false)
	if err != nil {
		return
	}
	post, err := fetchPostForUpdate(req, res, blog)
	if err != nil {
		return
	}
	res.SetLocal("blog", blog)
	res.SetLocal("post", post)
	res.SetLocal("css", "/static/css/admin/post.css")
	res.SetLocal("js", "/static/js/admin/post.js")
	res.Templates("admin/post.html", "header.html", "footer.html")
}
Beispiel #4
0
func (p *Page) _processRequest(res *wcg.Response, req *wcg.Request) {
	// instance of Page
	pi := &Page{}
	pi.App = p.App
	pi.Title = p.Title
	pi.Path = p.Path
	pi.assetPath = p.assetPath
	if p.templates != nil {
		pi.templates = make([]string, len(p.templates))
		for i := range p.templates {
			pi.templates[i] = p.templates[i]
		}
	}
	pi.Ogp("site_name", "SPEEDLAND Project")
	// pre process to update page attributes
	if p.handler != nil {
		p.handler(res, req, pi)
		if res.IsClosed() {
			return
		}
	}

	// automatically set ogp attributes if not set.
	if _, ok := pi.ogp["title"]; !ok {
		pi.Ogp("title", fmt.Sprintf("%s: %s", pi.App.Title, pi.Title))
	}
	if _, ok := pi.ogp["url"]; !ok {
		pi.Ogp("url", wcg.AbsoluteUrl(req, req.URL().RequestURI()))
	}

	// set default OGP from app settings.
	for k, v := range pi.App.DefaultOgp {
		pi.Ogp(k, v)
	}

	res.SetLocal("Page", pi)
	res.SetLocal("Ogp", pi.ogp)
	res.SetLocal("Request", req)
	res.SetLocal("TrackingCode", TrackingCode)
	res.SetLocal("__JsBundle__", pi.GetAssetPath())
	res.SetLocal("__APP_COMMIT", APP_COMMIT)
	res.SetLocal("__APP_TIMESTAMP", APP_TIMESTAMP)
	template_paths := []string{"./header.html", "./footer.html"}
	res.Templates(append(pi.GetTemplates(), template_paths...)...)
}
Beispiel #5
0
func showPostHandler(res *wcg.Response, req *wcg.Request) {
	blog, _, err := fetchBlog(res, req, false)
	if err != nil {
		return
	}
	post, err := fetchPost(res, req, blog)
	if err != nil {
		return
	}
	res.SetLocal("Og", &supports.Og{Title: post.Title, Type: "article",
		Url: wcg.AbsoluteUrl(req, req.URL().Path), SiteName: blog.Title,
		Description: wcg.Shorten(post.Content, 80),
	})
	res.SetLocal("blog", blog)
	res.SetLocal("post", post)
	res.SetLocal("is_owner", post.OwnerId == req.User.Id())
	res.SetLocal("js", "/static/js/post.js")
	res.Templates("post.html", "header.html", "footer.html", "parts/post_part.html")
}