コード例 #1
0
ファイル: pages.go プロジェクト: denisbakhtin/medical
//PageShow handles /pages/:id route
func PageShow(c *gin.Context) {
	db := models.GetDB()
	session := sessions.Default(c)

	idslug := c.Param("idslug")
	id := helpers.Atouint(strings.Split(idslug, "-")[0])
	page := &models.Page{}
	db.First(page, id)
	if page.ID == 0 || !page.Published {
		c.HTML(404, "errors/404", nil)
		return
	}
	//redirect to canonical url
	if c.Request.URL.Path != page.URL() {
		c.Redirect(303, page.URL())
		return
	}
	c.HTML(200, "pages/show", gin.H{
		"Page":            page,
		"Title":           page.Name,
		"Active":          page.URL(),
		"MetaDescription": page.MetaDescription,
		"MetaKeywords":    page.MetaKeywords,
		"Authenticated":   (session.Get("user_id") != nil),
	})
}
コード例 #2
0
ファイル: articles.go プロジェクト: denisbakhtin/medical
//ArticleShow handles GET /articles/:id-slug route
func ArticleShow(c *gin.Context) {
	db := models.GetDB()
	session := sessions.Default(c)

	idslug := c.Param("idslug")
	id := helpers.Atouint(strings.Split(idslug, "-")[0])
	article := &models.Article{}
	db.First(article, id)
	if article.ID == 0 || !article.Published {
		c.HTML(404, "errors/404", nil)
		return
	}
	//redirect to canonical url
	if c.Request.URL.Path != article.URL() {
		c.Redirect(303, article.URL())
		return
	}
	var testimonials []models.Review
	db.Where("published = ? and article_id = ?", true, article.ID).Order("created_at desc").Find(&testimonials)
	topComments := models.GetTopComments(article.ID)
	comments := models.GetComments(article.ID)
	article.Comments = append(topComments, comments...)
	imageurl := ""
	if img := article.GetImage(); len(img) > 0 {
		imageurl = fmt.Sprintf("http://%s%s", c.Request.Host, img)
	}
	flashes := session.Flashes()
	session.Save()
	c.HTML(200, "articles/show", gin.H{
		"Article":         article,
		"Testimonials":    testimonials,
		"Title":           article.Name,
		"Active":          "/articles",
		"MetaDescription": article.MetaDescription,
		"MetaKeywords":    article.MetaKeywords,
		"Ogheadprefix":    "og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#",
		"Ogtitle":         article.Name,
		"Ogurl":           fmt.Sprintf("http://%s/articles/%d", c.Request.Host, article.ID),
		"Ogtype":          "article",
		"Ogdescription":   article.Excerpt,
		"Ogimage":         imageurl,
		"Flash":           flashes,
		"Authenticated":   (session.Get("user_id") != nil),
	})
}