Documentation ¶
Index ¶
- Variables
- type SuffixInfo
- type Type
- type Types
- func (t Types) BySuffix(suffix string) []Type
- func (t Types) GetByMainSubType(mainType, subType string) (tp Type, found bool)
- func (t Types) GetByType(tp string) (Type, bool)
- func (t Types) GetFirstBySuffix(suffix string) (Type, SuffixInfo, bool)
- func (t Types) Len() int
- func (t Types) Less(i, j int) bool
- func (t Types) Swap(i, j int)
Constants ¶
This section is empty.
Variables ¶
var ( HTMLType = newMediaType("text", "html", []string{"html"}) JSONType = newMediaType("application", "json", []string{"json"}) TOMLType = newMediaType("application", "toml", []string{"toml"}) MarkdownType = newMediaType("text", "markdown", []string{"md", "markdown"}) OctetType = newMediaType("application", "octet-stream", nil) TextType = newMediaType("text", "plain", []string{"txt"}) )
Definitions from https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types etc. Note that from Hugo 0.44 we only set Suffix if it is part of the MIME type.
var DefaultTypes = Types{ HTMLType, MarkdownType, TOMLType, TextType, }
DefaultTypes is the default media types supported by Hugo.
Functions ¶
This section is empty.
Types ¶
type SuffixInfo ¶
SuffixInfo holds information about a Type's suffix.
type Type ¶
type Type struct { MainType string `json:"mainType"` // i.e. text SubType string `json:"subType"` // i.e. html Delimiter string `json:"delimiter"` // e.g. "." // FirstSuffix holds the first suffix defined for this Type. FirstSuffix SuffixInfo `json:"firstSuffix"` // contains filtered or unexported fields }
Type (also known as MIME type and content type) is a two-part identifier for file formats and format contents transmitted on the Internet. For Hugo's use case, we use the top-level type name / subtype name + suffix. One example would be application/svg+xml If suffix is not provided, the sub type will be used. See // https://en.wikipedia.org/wiki/Media_type
func FromStringAndExt ¶
FromStringAndExt creates a Type from a MIME string and a given extension.
func (Type) Type ¶
Type returns a string representing the main- and sub-type of a media type, e.g. "text/css". A suffix identifier will be appended after a "+" if set, e.g. "image/svg+xml". Hugo will register a set of default media types. These can be overridden by the user in the configuration, by defining a media type with the same Type.
type Types ¶
type Types []Type
Types is a slice of media types.
func DecodeTypes ¶
DecodeTypes takes a list of media type configurations and merges those, in the order given, with the Hugo defaults as the last resort.
func (Types) GetByMainSubType ¶
GetByMainSubType gets a media type given a main and a sub type e.g. "text" and "plain". It will return false if no format could be found, or if the combination given is ambiguous. The lookup is case insensitive.
func (Types) GetFirstBySuffix ¶
func (t Types) GetFirstBySuffix(suffix string) (Type, SuffixInfo, bool)
GetFirstBySuffix will return the first type matching the given suffix.