diff --git a/config.yaml b/config.yaml index 15f1a97..fb97bfd 100644 --- a/config.yaml +++ b/config.yaml @@ -99,4 +99,9 @@ site: - name: link: avatar: - description: \ No newline at end of file + description: + + statistics: + enable: false + type: baidu + baidu: diff --git a/config/mSite.go b/config/mSite.go index c7a3833..127642b 100644 --- a/config/mSite.go +++ b/config/mSite.go @@ -1,9 +1,10 @@ package config type mSite struct { - Info mInfo `yaml:"info"` - Menu mMenu `yaml:"menu"` - Post mPost `yaml:"post"` - About mAbout `yaml:"about"` - Friend mFriend `yaml:"friend"` + Info mInfo `yaml:"info"` + Menu mMenu `yaml:"menu"` + Post mPost `yaml:"post"` + About mAbout `yaml:"about"` + Friend mFriend `yaml:"friend"` + Statistics mStatistics `yaml:"statistics"` } diff --git a/config/mStatistics.go b/config/mStatistics.go new file mode 100644 index 0000000..bb52e22 --- /dev/null +++ b/config/mStatistics.go @@ -0,0 +1,7 @@ +package config + +type mStatistics struct { + Enable bool `yaml:"enable"` + Type string `yaml:"type"` + Baidu string `yaml:"baidu"` +} diff --git a/internal/mApp/mHandler.go b/internal/mApp/mHandler.go index 3cd0bad..d7224cc 100644 --- a/internal/mApp/mHandler.go +++ b/internal/mApp/mHandler.go @@ -53,6 +53,21 @@ func (ma *MApp) IndexHandler(ctx *gin.Context) { }, } + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "index.html", resData) } @@ -114,6 +129,21 @@ func (ma *MApp) PostHandler(ctx *gin.Context) { }, } + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "post.html", resData) } @@ -193,6 +223,21 @@ func (ma *MApp) TagHandler(ctx *gin.Context) { }, } + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "tag.html", resData) } @@ -266,6 +311,21 @@ func (ma *MApp) CategoryHandler(ctx *gin.Context) { }, } + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "category.html", resData) } @@ -342,6 +402,21 @@ func (ma *MApp) ArchiveHandler(ctx *gin.Context) { }, } + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "archive.html", resData) } @@ -417,6 +492,21 @@ func (ma *MApp) SearchHandler(ctx *gin.Context) { }, } + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "search.html", resData) } @@ -486,6 +576,21 @@ func (ma *MApp) AboutHandler(ctx *gin.Context) { }, } + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "about.html", resData) } @@ -512,5 +617,21 @@ func (ma *MApp) FriendHandler(ctx *gin.Context) { "list": ma.Config.MSite.Friend.List, }, } + + // statistics + var statistics = gin.H{} + if ma.Config.MSite.Statistics.Enable { + switch ma.Config.MSite.Statistics.Type { + case "baidu": + statistics["enable"] = true + statistics["script"] = template.HTML(ma.Config.MSite.Statistics.Baidu) + break + default: + statistics["enable"] = false + } + } + + resData["statistics"] = statistics + ctx.HTML(http.StatusOK, "friend.html", resData) } diff --git a/templates/default/assets/css/global.css b/templates/default/assets/css/global.css index d5af0eb..32959de 100644 --- a/templates/default/assets/css/global.css +++ b/templates/default/assets/css/global.css @@ -76,6 +76,10 @@ a:hover { color: var(--secondary-text-color); } +.icp-text { + color: var(--secondary-text-color); +} + .main-logo { display: flex; } diff --git a/templates/default/html/about.html b/templates/default/html/about.html index 8dbe386..a256726 100644 --- a/templates/default/html/about.html +++ b/templates/default/html/about.html @@ -15,6 +15,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}