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 }}
diff --git a/templates/default/html/archive.html b/templates/default/html/archive.html index e0e9a6a..76bf355 100644 --- a/templates/default/html/archive.html +++ b/templates/default/html/archive.html @@ -13,6 +13,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}
diff --git a/templates/default/html/category.html b/templates/default/html/category.html index 56b09e4..c34dfb9 100644 --- a/templates/default/html/category.html +++ b/templates/default/html/category.html @@ -13,6 +13,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}
diff --git a/templates/default/html/friend.html b/templates/default/html/friend.html index 484236b..3ec8310 100644 --- a/templates/default/html/friend.html +++ b/templates/default/html/friend.html @@ -15,6 +15,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}
diff --git a/templates/default/html/index.html b/templates/default/html/index.html index 68bfed2..ac7400d 100644 --- a/templates/default/html/index.html +++ b/templates/default/html/index.html @@ -14,6 +14,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}
diff --git a/templates/default/html/post.html b/templates/default/html/post.html index 86b3567..b290c47 100644 --- a/templates/default/html/post.html +++ b/templates/default/html/post.html @@ -14,6 +14,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}
diff --git a/templates/default/html/search.html b/templates/default/html/search.html index 6d506b1..208962d 100644 --- a/templates/default/html/search.html +++ b/templates/default/html/search.html @@ -13,6 +13,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}
diff --git a/templates/default/html/tag.html b/templates/default/html/tag.html index 315a03a..7f14885 100644 --- a/templates/default/html/tag.html +++ b/templates/default/html/tag.html @@ -14,6 +14,11 @@ + + + {{ if .statistics.enable }} + {{ .statistics.script }} + {{ end }}