diff --git a/controllers/index.go b/controllers/index.go index a5df817..d644e67 100644 --- a/controllers/index.go +++ b/controllers/index.go @@ -1,6 +1,9 @@ package controllers -import "liteblog/models" +import ( + "liteblog/models" + "liteblog/syserrors" +) type IndexController struct { BaseController @@ -40,6 +43,24 @@ func (c *IndexController) Get() { c.TplName = "index.html" } + +// 显示文章 +// @router /details/:key [get] +func (c *IndexController) GetDetail() { + // 得到页面传过来的key + key := c.Ctx.Input.Param(":key") + // 到数据查询对应key的文章 + note, err := models.QueryNoteByKey(key) + + if err != nil { + c.Abort500(syserrors.NewError("文章不存在", err)) + } + + c.Data["note"] = note + c.TplName = "details.html" + +} + //留言 // @router /message [get] func (c *IndexController) GetMessage() { diff --git a/models/note.go b/models/note.go index 55352f5..cc5650a 100644 --- a/models/note.go +++ b/models/note.go @@ -32,6 +32,11 @@ func QueryNoteCount(title string) (count int, err error) { return count, err } +func QueryNoteByKey(key string) (note Note, err error) { + err = db.Model(&Note{}).First(¬e, "`key` = ?", key).Error + return note, err +} + func SaveNote(n *Note) error { return db.Save(n).Error } \ No newline at end of file diff --git a/views/details.html b/views/details.html index fcbfc0f..d2cdd55 100755 --- a/views/details.html +++ b/views/details.html @@ -4,62 +4,15 @@ 评论-闲言轻博客 - - + {{ template "shares/link.html" .}} -
-
-

- - - - -

-
-
-
- - -
-
-
-
- - - - -
-
- - - -
-
- -
+ {{ template "shares/header.html" .}}
-
-

拥有诗意的心态,才能拥有诗意的生活

-
发布于:刚刚
-

父爱如山,不善表达。回想十多年前,总记得父亲有个宽厚的肩膀,小小的自己跨坐在上面,越过人山人海去看更广阔的天空,那个时候期望自己有一双翅膀,能够像鸟儿一样飞得高,看得远。虽然父亲有时会和自己开玩笑,但在做错事的时候会受到严厉的训斥。父亲有双粗糙的大手掌,手把手教我走路、骑车,却会在该放手的时刻果断地放开让自己去大胆尝试,那个时候期望快快长大,能够做自己想做的事,不用受父亲的“控制”。父亲是智慧树,他无所不知、无所不晓,虽然你有十万个为什么,但是也难不倒他。

- -
- 阅读 100000+ - -
-
+ {{ template "shares/note_tpl.html" .note}}
@@ -91,21 +44,6 @@
- - - + {{ template "shares/footer.html" .}} \ No newline at end of file diff --git a/views/index.html b/views/index.html index f61680b..b55895a 100755 --- a/views/index.html +++ b/views/index.html @@ -16,12 +16,7 @@ {{ range .notes }}
-
-

{{ .Title }}

-
发布于:{{ date .UpdatedAt "Y-m-d H:i:s"}}
-

{{ .Summary }}

- -
+ {{ template "shares/note_summary_tpl.html" .}}
评论 diff --git a/views/shares/note_summary_tpl.html b/views/shares/note_summary_tpl.html new file mode 100644 index 0000000..4a26b11 --- /dev/null +++ b/views/shares/note_summary_tpl.html @@ -0,0 +1,5 @@ +
+

{{ .Title }}

+
发布于:{{ date .UpdatedAt "Y-m-d H:i:s"}}
+

{{ .Summary }}

+
\ No newline at end of file diff --git a/views/shares/note_tpl.html b/views/shares/note_tpl.html new file mode 100644 index 0000000..c1e9408 --- /dev/null +++ b/views/shares/note_tpl.html @@ -0,0 +1,17 @@ +
+

{{ .Title }}

+
发布于:{{ date .UpdatedAt "Y-m-d H:i:s"}}
+

{{ str2html .Content }}

+
+ \ No newline at end of file