diff --git a/cmd/renderer/main.go b/cmd/renderer/main.go index 46419a7..71bb1e2 100644 --- a/cmd/renderer/main.go +++ b/cmd/renderer/main.go @@ -52,7 +52,7 @@ func main() { logrus.Fatal(err) } - templateFuncs := &templates.Funcs{Version: Version} + templateFuncs := &templates.Funcs{Version: Version, Site: config.Site} err = templates.Load(templateFuncs) if err != nil { logrus.Fatal(err) diff --git a/pkg/config/config.go b/pkg/config/config.go index 68f1f8d..b13c52e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -23,6 +23,10 @@ type Content struct { PostsPerPage int `mapstructure:"postsPerPage"` } +type Site struct { + YandexKey string `mapstructure:"yandexKey"` +} + // Config contains application configuration type Config struct { Verbose string `mapstructure:"verbose"` @@ -30,6 +34,7 @@ type Config struct { Addr string `mapstructure:"addr"` Unix string `mapstructure:"unix"` Content Content `mapstructure:"content"` + Site Site `mapstructure:"site"` } // initialize default values on app-start @@ -50,6 +55,8 @@ func init() { pflag.String("content.pinned", "contact", "pinned page slug") pflag.Int("content.postsPerPage", 5, "amount of posts per page") + pflag.String("site.yandexKey", "", "yandex analytics key") + pflag.Parse() viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) diff --git a/pkg/templates/analytics.go.tmpl b/pkg/templates/analytics.go.tmpl new file mode 100644 index 0000000..fd17f60 --- /dev/null +++ b/pkg/templates/analytics.go.tmpl @@ -0,0 +1,18 @@ +{{ with $yk := getYaKey }} +{{ if $yk }} + + + + +{{ end }} +{{ end }} \ No newline at end of file diff --git a/pkg/templates/funcs.go b/pkg/templates/funcs.go index 41d1927..4c4254f 100644 --- a/pkg/templates/funcs.go +++ b/pkg/templates/funcs.go @@ -4,10 +4,13 @@ import ( "html/template" "net/url" "sync" + + "code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config" ) type Funcs struct { Version string + Site config.Site compiledJSAppURL string @@ -54,6 +57,10 @@ func (f *Funcs) getBlogURL() string { return URLBlog } +func (f *Funcs) getYaKey() string { + return f.Site.YandexKey +} + // Use returns a func map with template helpers functions func (f *Funcs) Use() template.FuncMap { return template.FuncMap{ @@ -62,5 +69,6 @@ func (f *Funcs) Use() template.FuncMap { "getJSAppURL": f.getJSAppURL, "getIndexURL": f.getIndexURL, "getBlogURL": f.getBlogURL, + "getYaKey": f.getYaKey, } } diff --git a/pkg/templates/head.go.tmpl b/pkg/templates/head.go.tmpl index 4c805e2..63e5564 100644 --- a/pkg/templates/head.go.tmpl +++ b/pkg/templates/head.go.tmpl @@ -6,4 +6,6 @@