Add support for configuring opening and closing delimiters for plugins

This commit is contained in:
James Mills 2023-08-20 03:41:02 +10:00
parent f12b2286d9
commit b23a2eb29e
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

14
main.go
View File

@ -447,8 +447,8 @@ func getVars(path string, globals Vars) (Vars, string, error) {
// Render expanding zs plugins and variables // Render expanding zs plugins and variables
func render(s string, vars Vars) (string, error) { func render(s string, vars Vars) (string, error) {
openingDelimiter := "{{" openingDelimiter := viper.GetString("opening-delim")
closingDelimiter := "}}" closingDelimiter := viper.GetString("closing-delim")
out := &bytes.Buffer{} out := &bytes.Buffer{}
for { for {
@ -720,7 +720,7 @@ func init() {
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().BoolP("debug", "D", false, "enable debug logging $($ZS_DEBUG)") 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().StringVarP(&configFile, "config", "C", "", "config file (default: .zs/config.yml)")
RootCmd.PersistentFlags().StringSliceP("extensions", "e", MapKeys(Extensions), "override and enable specific extensions") 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().BoolP("production", "p", false, "enable production mode ($ZS_PRODUCTION)")
@ -729,6 +729,9 @@ func init() {
RootCmd.PersistentFlags().StringP("keywords", "k", "", "site keywords ($ZS_KEYWORDS)") RootCmd.PersistentFlags().StringP("keywords", "k", "", "site keywords ($ZS_KEYWORDS)")
RootCmd.PersistentFlags().StringSliceP("vars", "v", nil, "additional variables") RootCmd.PersistentFlags().StringSliceP("vars", "v", nil, "additional variables")
RootCmd.PersistentFlags().StringP("opening-delim", "o", "{{", "opening delimiter for plugins")
RootCmd.PersistentFlags().StringP("closing-delim", "c", "{{", "closing delimiter for plugins")
viper.BindPFlag("debug", RootCmd.PersistentFlags().Lookup("debug")) viper.BindPFlag("debug", RootCmd.PersistentFlags().Lookup("debug"))
viper.SetDefault("debug", false) viper.SetDefault("debug", false)
@ -750,6 +753,11 @@ func init() {
viper.BindPFlag("vars", RootCmd.PersistentFlags().Lookup("vars")) viper.BindPFlag("vars", RootCmd.PersistentFlags().Lookup("vars"))
viper.SetDefault("vars", "") viper.SetDefault("vars", "")
viper.BindPFlag("opening-delim", RootCmd.PersistentFlags().Lookup("opening-delim"))
viper.SetDefault("opening-delim", "{{")
viper.BindPFlag("closing-delim", RootCmd.PersistentFlags().Lookup("closing-delim"))
viper.SetDefault("closing-delim", "}}")
ServeCmd.Flags().StringP("bind", "b", ":8000", "set the [<address>]:<port> to listen on") ServeCmd.Flags().StringP("bind", "b", ":8000", "set the [<address>]:<port> to listen on")
ServeCmd.Flags().StringP("root", "r", PUBDIR, "set the root directory to serve") ServeCmd.Flags().StringP("root", "r", PUBDIR, "set the root directory to serve")