mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
@@ -14,6 +14,9 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
"github.com/gohugoio/hugo/parser/metadecoders"
|
||||
"github.com/spf13/afero"
|
||||
@@ -21,9 +24,23 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ValidConfigFileExtensions = []string{"toml", "yaml", "yml", "json"}
|
||||
ValidConfigFileExtensions = []string{"toml", "yaml", "yml", "json"}
|
||||
validConfigFileExtensionsMap map[string]bool = make(map[string]bool)
|
||||
)
|
||||
|
||||
func init() {
|
||||
for _, ext := range ValidConfigFileExtensions {
|
||||
validConfigFileExtensionsMap[ext] = true
|
||||
}
|
||||
}
|
||||
|
||||
// IsValidConfigFilename returns whether filename is one of the supported
|
||||
// config formats in Hugo.
|
||||
func IsValidConfigFilename(filename string) bool {
|
||||
ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(filename), "."))
|
||||
return validConfigFileExtensionsMap[ext]
|
||||
}
|
||||
|
||||
// FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests.
|
||||
func FromConfigString(config, configType string) (Provider, error) {
|
||||
v := newViper()
|
||||
|
Reference in New Issue
Block a user