From 320cc026eedc305a13284f79c6ffdf4e7c3246dc Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Sun, 26 Mar 2023 12:57:17 +1000 Subject: [PATCH] Fix setting extensions via config --- main.go | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 836ca4e..bcfad66 100644 --- a/main.go +++ b/main.go @@ -70,18 +70,6 @@ var Parser goldmark.Markdown var ( configFile string enabledExtensions []string - - // Title site title - Title string - - // Description site description - Description string - - // Keywords site keywords - Keywords string - - // Production is a global variable to conditionally build for production - Production = false ) // Extensions is a mapping of name to extension and the default set of extensions enabled @@ -163,7 +151,7 @@ var RootCmd = &cobra.Command{ } var extensions []goldmark.Extender - for _, name := range enabledExtensions { + for _, name := range viper.GetStringSlice("extensions") { if extender, valid := Extensions[name]; valid { extensions = append(extensions, extender) } else { @@ -329,7 +317,7 @@ func globals() Vars { "keywords": viper.GetString("keywords"), } - if Production { + if viper.GetBool("production") { vars["production"] = "1" } @@ -666,15 +654,18 @@ func init() { RootCmd.PersistentFlags().BoolP("debug", "D", false, "enable debug logging $($ZS_DEBUG)") RootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "config file (default: .zs/config.yml)") - RootCmd.PersistentFlags().StringSliceVarP(&enabledExtensions, "extensions", "e", MapKeys(Extensions), "override and enable specific extensions") - RootCmd.PersistentFlags().BoolVarP(&Production, "production", "p", false, "enable production mode ($ZS_PRODUCTION)") - RootCmd.PersistentFlags().StringVarP(&Title, "title", "t", "", "site title ($ZS_TITLE)") - RootCmd.PersistentFlags().StringVarP(&Description, "description", "d", "", "site description ($ZS_DESCRIPTION)") - RootCmd.PersistentFlags().StringVarP(&Keywords, "keywords", "k", "", "site keywords ($ZS_KEYWORDS)") + RootCmd.PersistentFlags().StringSliceP("extensions", "e", MapKeys(Extensions), "override and enable specific extensions") + RootCmd.PersistentFlags().BoolP("production", "p", false, "enable production mode ($ZS_PRODUCTION)") + RootCmd.PersistentFlags().StringP("title", "t", "", "site title ($ZS_TITLE)") + RootCmd.PersistentFlags().StringP("description", "d", "", "site description ($ZS_DESCRIPTION)") + RootCmd.PersistentFlags().StringP("keywords", "k", "", "site keywords ($ZS_KEYWORDS)") viper.BindPFlag("debug", RootCmd.PersistentFlags().Lookup("debug")) viper.SetDefault("debug", false) + viper.BindPFlag("extensions", RootCmd.PersistentFlags().Lookup("extensions")) + viper.SetDefault("extensions", MapKeys(Extensions)) + viper.BindPFlag("production", RootCmd.PersistentFlags().Lookup("production")) viper.SetDefault("production", false) -- 2.43.0