hugo: github.com/gohugoio/hugo/media Index | Files

package media

import "github.com/gohugoio/hugo/media"

Index

Package Files

docshelper.go mediaType.go

Variables

var (
    CalendarType   = Type{MainType: "text", SubType: "calendar", Suffixes: []string{"ics"}, Delimiter: defaultDelimiter}
    CSSType        = Type{MainType: "text", SubType: "css", Suffixes: []string{"css"}, Delimiter: defaultDelimiter}
    SCSSType       = Type{MainType: "text", SubType: "x-scss", Suffixes: []string{"scss"}, Delimiter: defaultDelimiter}
    SASSType       = Type{MainType: "text", SubType: "x-sass", Suffixes: []string{"sass"}, Delimiter: defaultDelimiter}
    CSVType        = Type{MainType: "text", SubType: "csv", Suffixes: []string{"csv"}, Delimiter: defaultDelimiter}
    HTMLType       = Type{MainType: "text", SubType: "html", Suffixes: []string{"html"}, Delimiter: defaultDelimiter}
    JavascriptType = Type{MainType: "application", SubType: "javascript", Suffixes: []string{"js"}, Delimiter: defaultDelimiter}
    JSONType       = Type{MainType: "application", SubType: "json", Suffixes: []string{"json"}, Delimiter: defaultDelimiter}
    RSSType        = Type{MainType: "application", SubType: "rss", Suffixes: []string{"xml"}, Delimiter: defaultDelimiter, /* contains filtered or unexported fields */}
    XMLType        = Type{MainType: "application", SubType: "xml", Suffixes: []string{"xml"}, Delimiter: defaultDelimiter}
    SVGType        = Type{MainType: "image", SubType: "svg", Suffixes: []string{"svg"}, Delimiter: defaultDelimiter, /* contains filtered or unexported fields */}
    TextType       = Type{MainType: "text", SubType: "plain", Suffixes: []string{"txt"}, Delimiter: defaultDelimiter}
    TOMLType       = Type{MainType: "application", SubType: "toml", Suffixes: []string{"toml"}, Delimiter: defaultDelimiter}
    YAMLType       = Type{MainType: "application", SubType: "yaml", Suffixes: []string{"yaml", "yml"}, Delimiter: defaultDelimiter}

    // Common image types
    PNGType  = Type{MainType: "image", SubType: "png", Suffixes: []string{"png"}, Delimiter: defaultDelimiter}
    JPEGType = Type{MainType: "image", SubType: "jpeg", Suffixes: []string{"jpg", "jpeg"}, Delimiter: defaultDelimiter}
    GIFType  = Type{MainType: "image", SubType: "gif", Suffixes: []string{"gif"}, Delimiter: defaultDelimiter}
    TIFFType = Type{MainType: "image", SubType: "tiff", Suffixes: []string{"tif", "tiff"}, Delimiter: defaultDelimiter}
    BMPType  = Type{MainType: "image", SubType: "bmp", Suffixes: []string{"bmp"}, Delimiter: defaultDelimiter}

    // Common video types
    AVIType  = Type{MainType: "video", SubType: "x-msvideo", Suffixes: []string{"avi"}, Delimiter: defaultDelimiter}
    MPEGType = Type{MainType: "video", SubType: "mpeg", Suffixes: []string{"mpg", "mpeg"}, Delimiter: defaultDelimiter}
    MP4Type  = Type{MainType: "video", SubType: "mp4", Suffixes: []string{"mp4"}, Delimiter: defaultDelimiter}
    OGGType  = Type{MainType: "video", SubType: "ogg", Suffixes: []string{"ogv"}, Delimiter: defaultDelimiter}
    WEBMType = Type{MainType: "video", SubType: "webm", Suffixes: []string{"webm"}, Delimiter: defaultDelimiter}
    GPPType  = Type{MainType: "video", SubType: "3gpp", Suffixes: []string{"3gpp", "3gp"}, Delimiter: defaultDelimiter}

    OctetType = Type{MainType: "application", SubType: "octet-stream"}
)

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{
    CalendarType,
    CSSType,
    CSVType,
    SCSSType,
    SASSType,
    HTMLType,
    JavascriptType,
    JSONType,
    RSSType,
    XMLType,
    SVGType,
    TextType,
    OctetType,
    YAMLType,
    TOMLType,
    PNGType,
    JPEGType,
    AVIType,
    MPEGType,
    MP4Type,
    OGGType,
    WEBMType,
    GPPType,
}

DefaultTypes is the default media types supported by Hugo.

type Type Uses

type Type struct {
    MainType string `json:"mainType"` // i.e. text
    SubType  string `json:"subType"`  // i.e. html

    Delimiter string `json:"delimiter"` // e.g. "."

    // TODO(bep) make this a string to make it hashable + method
    Suffixes []string `json:"suffixes"`
    // 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 Uses

func FromStringAndExt(t, ext string) (Type, error)

FromStringAndExt is same as FromString, but adds the file extension to the type.

func (Type) FullSuffix Uses

func (m Type) FullSuffix() string

FullSuffix returns the file suffix with any delimiter prepended.

func (Type) MarshalJSON Uses

func (m Type) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of m.

func (Type) String Uses

func (m Type) String() string

func (Type) Suffix Uses

func (m Type) Suffix() string

Suffix returns the file suffix without any delmiter prepended.

func (Type) Type Uses

func (m Type) Type() string

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 Uses

type Types []Type

Types is a slice of media types.

func DecodeTypes Uses

func DecodeTypes(mms ...map[string]interface{}) (Types, error)

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) BySuffix Uses

func (t Types) BySuffix(suffix string) []Type

BySuffix will return all media types matching a suffix.

func (Types) GetByMainSubType Uses

func (t Types) GetByMainSubType(mainType, subType string) (tp Type, found bool)

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) GetBySuffix Uses

func (t Types) GetBySuffix(suffix string) (tp Type, found bool)

GetBySuffix gets a media type given as suffix, e.g. "html". It will return false if no format could be found, or if the suffix given is ambiguous. The lookup is case insensitive.

func (Types) GetByType Uses

func (t Types) GetByType(tp string) (Type, bool)

GetByType returns a media type for tp.

func (Types) GetFirstBySuffix Uses

func (t Types) GetFirstBySuffix(suffix string) (Type, bool)

GetFirstBySuffix will return the first media type matching the given suffix.

func (Types) Len Uses

func (t Types) Len() int

func (Types) Less Uses

func (t Types) Less(i, j int) bool

func (Types) Swap Uses

func (t Types) Swap(i, j int)

Package media imports 8 packages (graph) and is imported by 225 packages. Updated 2020-03-21. Refresh now. Tools for package owners.