media

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CalendarType   = newMediaType("text", "calendar", []string{"ics"})
	CSSType        = newMediaType("text", "css", []string{"css"})
	SCSSType       = newMediaType("text", "x-scss", []string{"scss"})
	SASSType       = newMediaType("text", "x-sass", []string{"sass"})
	CSVType        = newMediaType("text", "csv", []string{"csv"})
	HTMLType       = newMediaType("text", "html", []string{"html"})
	JavascriptType = newMediaType("text", "javascript", []string{"js", "jsm", "mjs"})
	TypeScriptType = newMediaType("text", "typescript", []string{"ts"})
	TSXType        = newMediaType("text", "tsx", []string{"tsx"})
	JSXType        = newMediaType("text", "jsx", []string{"jsx"})

	JSONType           = newMediaType("application", "json", []string{"json"})
	WebAppManifestType = newMediaTypeWithMimeSuffix("application", "manifest", "json", []string{"webmanifest"})
	RSSType            = newMediaTypeWithMimeSuffix("application", "rss", "xml", []string{"xml", "rss"})
	XMLType            = newMediaType("application", "xml", []string{"xml"})
	SVGType            = newMediaTypeWithMimeSuffix("image", "svg", "xml", []string{"svg"})
	TextType           = newMediaType("text", "plain", []string{"txt"})
	TOMLType           = newMediaType("application", "toml", []string{"toml"})
	YAMLType           = newMediaType("application", "yaml", []string{"yaml", "yml"})

	// Common image types
	PNGType  = newMediaType("image", "png", []string{"png"})
	JPEGType = newMediaType("image", "jpeg", []string{"jpg", "jpeg", "jpe", "jif", "jfif"})
	GIFType  = newMediaType("image", "gif", []string{"gif"})
	TIFFType = newMediaType("image", "tiff", []string{"tif", "tiff"})
	BMPType  = newMediaType("image", "bmp", []string{"bmp"})
	WEBPType = newMediaType("image", "webp", []string{"webp"})

	// Common font types
	TrueTypeFontType = newMediaType("font", "ttf", []string{"ttf"})
	OpenTypeFontType = newMediaType("font", "otf", []string{"otf"})

	// Common document types
	PDFType      = newMediaType("application", "pdf", []string{"pdf"})
	MarkdownType = newMediaType("text", "markdown", []string{"md", "markdown"})

	// Common video types
	AVIType  = newMediaType("video", "x-msvideo", []string{"avi"})
	MPEGType = newMediaType("video", "mpeg", []string{"mpg", "mpeg"})
	MP4Type  = newMediaType("video", "mp4", []string{"mp4"})
	OGGType  = newMediaType("video", "ogg", []string{"ogv"})
	WEBMType = newMediaType("video", "webm", []string{"webm"})
	GPPType  = newMediaType("video", "3gpp", []string{"3gpp", "3gp"})

	OctetType = newMediaType("application", "octet-stream", nil)
)

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.

DefaultTypes is the default media types supported by Hugo.

Functions

This section is empty.

Types

type SuffixInfo added in v1.0.0

type SuffixInfo struct {
	Suffix     string `json:"suffix"`
	FullSuffix string `json:"fullSuffix"`
}

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 FromContent added in v1.0.0

func FromContent(types Types, extensionHints []string, content []byte) Type

FromContent resolve the Type primarily using http.DetectContentType. If http.DetectContentType resolves to application/octet-stream, a zero Type is returned. If http.DetectContentType resolves to text/plain or application/xml, we try to get more specific using types and ext.

func FromStringAndExt added in v0.45.1

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

FromStringAndExt creates a Type from a MIME string and a given extension.

func WithDelimiterAndSuffixes added in v1.0.0

func WithDelimiterAndSuffixes(t Type, delimiter, suffixesCSV string) Type

WithDelimiterAndSuffixes is used in tests.

func (Type) IsText added in v1.0.0

func (m Type) IsText() bool

IsText returns whether this Type is a text format. Note that this may currently return false negatives. TODO(bep) improve

func (Type) IsZero added in v1.0.0

func (m Type) IsZero() bool

IsZero reports whether this Type represents a zero value. For internal use.

func (Type) MarshalJSON

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

MarshalJSON returns the JSON encoding of m. For internal use.

func (Type) String

func (m Type) String() string

For internal use.

func (Type) Suffixes added in v0.45.1

func (m Type) Suffixes() []string

Suffixes returns all valid file suffixes for this type.

func (Type) Type

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

type Types []Type

Types is a slice of media types.

func DecodeTypes

func DecodeTypes(mms ...map[string]any) (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 added in v1.0.0

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

BySuffix will return all media types matching a suffix.

func (Types) GetByMainSubType added in v0.45.1

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

func (t Types) GetBySuffix(suffix string) (tp Type, si SuffixInfo, 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

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

GetByType returns a media type for tp.

func (Types) GetFirstBySuffix added in v0.45.1

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

GetFirstBySuffix will return the first type matching the given suffix.

func (Types) Len

func (t Types) Len() int

func (Types) Less

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

func (Types) Swap

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL