@@ -22,16 +22,21 @@ import (
2222 "github.com/mitchellh/mapstructure"
2323)
2424
25+ const (
26+ defaultDelimiter = "."
27+ )
28+
2529// A media type (also known as MIME type and content type) is a two-part identifier for
2630// file formats and format contents transmitted on the Internet.
2731// For Hugo's use case, we use the top-level type name / subtype name + suffix.
2832// One example would be image/jpeg+jpg
2933// If suffix is not provided, the sub type will be used.
3034// See // https://en.wikipedia.org/wiki/Media_type
3135type Type struct {
32- MainType string // i.e. text
33- SubType string // i.e. html
34- Suffix string // i.e html
36+ MainType string // i.e. text
37+ SubType string // i.e. html
38+ Suffix string // i.e html
39+ Delimiter string // defaults to "."
3540}
3641
3742// FromTypeString creates a new Type given a type sring on the form MainType/SubType and
@@ -54,7 +59,7 @@ func FromString(t string) (Type, error) {
5459 suffix = subParts [1 ]
5560 }
5661
57- return Type {MainType : mainType , SubType : subType , Suffix : suffix }, nil
62+ return Type {MainType : mainType , SubType : subType , Suffix : suffix , Delimiter : defaultDelimiter }, nil
5863}
5964
6065// Type returns a string representing the main- and sub-type of a media type, i.e. "text/css".
@@ -72,16 +77,21 @@ func (m Type) String() string {
7277 return fmt .Sprintf ("%s/%s" , m .MainType , m .SubType )
7378}
7479
80+ // FullSuffix returns the file suffix with any delimiter prepended.
81+ func (m Type ) FullSuffix () string {
82+ return m .Delimiter + m .Suffix
83+ }
84+
7585var (
76- CalendarType = Type {"text" , "calendar" , "ics" }
77- CSSType = Type {"text" , "css" , "css" }
78- CSVType = Type {"text" , "csv" , "csv" }
79- HTMLType = Type {"text" , "html" , "html" }
80- JavascriptType = Type {"application" , "javascript" , "js" }
81- JSONType = Type {"application" , "json" , "json" }
82- RSSType = Type {"application" , "rss" , "xml" }
83- XMLType = Type {"application" , "xml" , "xml" }
84- TextType = Type {"text" , "plain" , "txt" }
86+ CalendarType = Type {"text" , "calendar" , "ics" , defaultDelimiter }
87+ CSSType = Type {"text" , "css" , "css" , defaultDelimiter }
88+ CSVType = Type {"text" , "csv" , "csv" , defaultDelimiter }
89+ HTMLType = Type {"text" , "html" , "html" , defaultDelimiter }
90+ JavascriptType = Type {"application" , "javascript" , "js" , defaultDelimiter }
91+ JSONType = Type {"application" , "json" , "json" , defaultDelimiter }
92+ RSSType = Type {"application" , "rss" , "xml" , defaultDelimiter }
93+ XMLType = Type {"application" , "xml" , "xml" , defaultDelimiter }
94+ TextType = Type {"text" , "plain" , "txt" , defaultDelimiter }
8595)
8696
8797var DefaultTypes = Types {
0 commit comments