hugo: github.com/gohugoio/hugo/parser/metadecoders Index | Files

package metadecoders

import "github.com/gohugoio/hugo/parser/metadecoders"

Index

Package Files

decoder.go format.go

Variables

var Default = Decoder{
    Delimiter: ',',
}

Default is a Decoder in its default configuration.

type Decoder Uses

type Decoder struct {
    // Delimiter is the field delimiter used in the CSV decoder. It defaults to ','.
    Delimiter rune

    // Comment, if not 0, is the comment character ued in the CSV decoder. Lines beginning with the
    // Comment character without preceding whitespace are ignored.
    Comment rune
}

Decoder provides some configuration options for the decoders.

func (Decoder) FormatFromContentString Uses

func (d Decoder) FormatFromContentString(data string) Format

FormatFromContentString tries to detect the format (JSON, YAML or TOML) in the given string. It return an empty string if no format could be detected.

func (Decoder) OptionsKey Uses

func (d Decoder) OptionsKey() string

OptionsKey is used in cache keys.

func (Decoder) Unmarshal Uses

func (d Decoder) Unmarshal(data []byte, f Format) (interface{}, error)

Unmarshal will unmarshall data in format f into an interface{}. This is what's needed for Hugo's /data handling.

func (Decoder) UnmarshalFileToMap Uses

func (d Decoder) UnmarshalFileToMap(fs afero.Fs, filename string) (map[string]interface{}, error)

UnmarshalFileToMap is the same as UnmarshalToMap, but reads the data from the given filename.

func (Decoder) UnmarshalStringTo Uses

func (d Decoder) UnmarshalStringTo(data string, typ interface{}) (interface{}, error)

UnmarshalStringTo tries to unmarshal data to a new instance of type typ.

func (Decoder) UnmarshalToMap Uses

func (d Decoder) UnmarshalToMap(data []byte, f Format) (map[string]interface{}, error)

UnmarshalToMap will unmarshall data in format f into a new map. This is what's needed for Hugo's front matter decoding.

type Format Uses

type Format string
const (
    // These are the supported metdata  formats in Hugo. Most of these are also
    // supported as /data formats.
    ORG  Format = "org"
    JSON Format = "json"
    TOML Format = "toml"
    YAML Format = "yaml"
    CSV  Format = "csv"
)

func FormatFromMediaType Uses

func FormatFromMediaType(m media.Type) Format

FormatFromMediaType gets the Format given a MIME type, empty string if unknown.

func FormatFromString Uses

func FormatFromString(formatStr string) Format

FormatFromString turns formatStr, typically a file extension without any ".", into a Format. It returns an empty string for unknown formats.

Package metadecoders imports 15 packages (graph) and is imported by 66 packages. Updated 2020-03-11. Refresh now. Tools for package owners.