diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-05-03 09:16:58 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-07-24 09:35:53 +0200 |
commit | 9f5a92078a3f388b52d597b5a59af5c933a112d2 (patch) | |
tree | 0b2b07e5b3a3f21877bc5585a4bdd76306a09dde /config | |
parent | 47953148b6121441d0147c960a99829c53b5a5ba (diff) | |
download | hugo-9f5a92078a3f388b52d597b5a59af5c933a112d2.tar.gz hugo-9f5a92078a3f388b52d597b5a59af5c933a112d2.zip |
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
Diffstat (limited to 'config')
-rw-r--r-- | config/configLoader.go | 2 | ||||
-rw-r--r-- | config/configProvider.go | 8 | ||||
-rw-r--r-- | config/env.go | 24 | ||||
-rw-r--r-- | config/env_test.go | 32 |
4 files changed, 62 insertions, 4 deletions
diff --git a/config/configLoader.go b/config/configLoader.go index b8aa3fda3..2e37a5b35 100644 --- a/config/configLoader.go +++ b/config/configLoader.go @@ -120,8 +120,6 @@ func RenameKeys(m map[string]interface{}) { func newViper() *viper.Viper { v := viper.New() - v.AutomaticEnv() - v.SetEnvPrefix("hugo") return v } diff --git a/config/configProvider.go b/config/configProvider.go index 31914c38b..187fb7b10 100644 --- a/config/configProvider.go +++ b/config/configProvider.go @@ -35,10 +35,14 @@ type Provider interface { // we do not attempt to split it into fields. func GetStringSlicePreserveString(cfg Provider, key string) []string { sd := cfg.Get(key) - if sds, ok := sd.(string); ok { + return toStringSlicePreserveString(sd) +} + +func toStringSlicePreserveString(v interface{}) []string { + if sds, ok := v.(string); ok { return []string{sds} } - return cast.ToStringSlice(sd) + return cast.ToStringSlice(v) } // SetBaseTestDefaults provides some common config defaults used in tests. diff --git a/config/env.go b/config/env.go index adf6f9b68..f482cd247 100644 --- a/config/env.go +++ b/config/env.go @@ -17,6 +17,7 @@ import ( "os" "runtime" "strconv" + "strings" ) // GetNumWorkerMultiplier returns the base value used to calculate the number @@ -31,3 +32,26 @@ func GetNumWorkerMultiplier() int { } return runtime.NumCPU() } + +// SetEnvVars sets vars on the form key=value in the oldVars slice. +func SetEnvVars(oldVars *[]string, keyValues ...string) { + for i := 0; i < len(keyValues); i += 2 { + setEnvVar(oldVars, keyValues[i], keyValues[i+1]) + } +} + +func SplitEnvVar(v string) (string, string) { + parts := strings.Split(v, "=") + return parts[0], parts[1] +} + +func setEnvVar(vars *[]string, key, value string) { + for i := range *vars { + if strings.HasPrefix((*vars)[i], key+"=") { + (*vars)[i] = key + "=" + value + return + } + } + // New var. + *vars = append(*vars, key+"="+value) +} diff --git a/config/env_test.go b/config/env_test.go new file mode 100644 index 000000000..594c3e871 --- /dev/null +++ b/config/env_test.go @@ -0,0 +1,32 @@ +// Copyright 2019 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestSetEnvVars(t *testing.T) { + t.Parallel() + assert := require.New(t) + vars := []string{"FOO=bar", "HUGO=cool", "BAR=foo"} + SetEnvVars(&vars, "HUGO", "rocking!", "NEW", "bar") + assert.Equal([]string{"FOO=bar", "HUGO=rocking!", "BAR=foo", "NEW=bar"}, vars) + + key, val := SplitEnvVar("HUGO=rocks") + assert.Equal("HUGO", key) + assert.Equal("rocks", val) +} |