mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-13 20:24:00 +02:00
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
This commit is contained in:
@@ -16,8 +16,6 @@ package metadecoders
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/media"
|
||||
)
|
||||
|
||||
type Format string
|
||||
@@ -33,6 +31,16 @@ const (
|
||||
XML Format = "xml"
|
||||
)
|
||||
|
||||
// FormatFromStrings returns the first non-empty Format from the given strings.
|
||||
func FormatFromStrings(ss ...string) Format {
|
||||
for _, s := range ss {
|
||||
if f := FormatFromString(s); f != "" {
|
||||
return f
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// FormatFromString turns formatStr, typically a file extension without any ".",
|
||||
// into a Format. It returns an empty string for unknown formats.
|
||||
func FormatFromString(formatStr string) Format {
|
||||
@@ -59,18 +67,6 @@ func FormatFromString(formatStr string) Format {
|
||||
return ""
|
||||
}
|
||||
|
||||
// FormatFromMediaType gets the Format given a MIME type, empty string
|
||||
// if unknown.
|
||||
func FormatFromMediaType(m media.Type) Format {
|
||||
for _, suffix := range m.Suffixes() {
|
||||
if f := FormatFromString(suffix); f != "" {
|
||||
return f
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// FormatFromContentString tries to detect the format (JSON, YAML, TOML or XML)
|
||||
// in the given string.
|
||||
// It return an empty string if no format could be detected.
|
||||
|
Reference in New Issue
Block a user