This commit is contained in:
2023-03-10 14:36:01 +08:00
parent d6d708bf5d
commit f8c1d183e4
2 changed files with 7 additions and 1 deletions
+4
View File
@@ -27,6 +27,7 @@ type Article struct {
Conf ArticleConf
Content string
Path string
Date string
}
func (a *Article) GetArticleById(id string) (*Article, error) {
@@ -59,6 +60,7 @@ func (a *Article) GetArticleByPath(path string) (*Article, error) {
t, err := time.Parse("2006-1-2 15:04", articleConf["date"])
if err == nil {
a.Conf.Time = t.Unix()
a.Date = time.Unix(a.Conf.Time, 0).Format("2006-01-02 15:04")
}
}
@@ -74,6 +76,7 @@ func (a *Article) GetArticleByPath(path string) (*Article, error) {
mtime := info.ModTime()
a.Conf.Time = mtime.Unix()
a.Content = parts[0]
a.Date = time.Unix(a.Conf.Time, 0).Format("2006-01-02 15:04")
}
return a, nil
}
@@ -92,6 +95,7 @@ func GetArticle(c *gin.Context) {
c.HTML(200, "article.html", gin.H{
"content": template.HTML(string(output)),
"title": article.Conf.Title,
"date": article.Date,
})
}