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

package output

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

Index

Package Files

docshelper.go layout.go outputFormat.go

Variables

var (
    AMPFormat = Format{
        Name:          "AMP",
        MediaType:     media.HTMLType,
        BaseName:      "index",
        Path:          "amp",
        Rel:           "amphtml",
        IsHTML:        true,
        Permalinkable: true,
    }

    CalendarFormat = Format{
        Name:        "Calendar",
        MediaType:   media.CalendarType,
        IsPlainText: true,
        Protocol:    "webcal://",
        BaseName:    "index",
        Rel:         "alternate",
    }

    CSSFormat = Format{
        Name:           "CSS",
        MediaType:      media.CSSType,
        BaseName:       "styles",
        IsPlainText:    true,
        Rel:            "stylesheet",
        NotAlternative: true,
    }
    CSVFormat = Format{
        Name:        "CSV",
        MediaType:   media.CSVType,
        BaseName:    "index",
        IsPlainText: true,
        Rel:         "alternate",
    }

    HTMLFormat = Format{
        Name:          "HTML",
        MediaType:     media.HTMLType,
        BaseName:      "index",
        Rel:           "canonical",
        IsHTML:        true,
        Permalinkable: true,

        Weight: 10,
    }

    JSONFormat = Format{
        Name:        "JSON",
        MediaType:   media.JSONType,
        BaseName:    "index",
        IsPlainText: true,
        Rel:         "alternate",
    }

    RobotsTxtFormat = Format{
        Name:        "ROBOTS",
        MediaType:   media.TextType,
        BaseName:    "robots",
        IsPlainText: true,
        Rel:         "alternate",
    }

    RSSFormat = Format{
        Name:      "RSS",
        MediaType: media.RSSType,
        BaseName:  "index",
        NoUgly:    true,
        Rel:       "alternate",
    }

    SitemapFormat = Format{
        Name:      "Sitemap",
        MediaType: media.XMLType,
        BaseName:  "sitemap",
        NoUgly:    true,
        Rel:       "sitemap",
    }
)

An ordered list of built-in output formats.

var DefaultFormats = Formats{
    AMPFormat,
    CalendarFormat,
    CSSFormat,
    CSVFormat,
    HTMLFormat,
    JSONFormat,
    RobotsTxtFormat,
    RSSFormat,
    SitemapFormat,
}

DefaultFormats contains the default output formats supported by Hugo.

type Format Uses

type Format struct {
    // The Name is used as an identifier. Internal output formats (i.e. HTML and RSS)
    // can be overridden by providing a new definition for those types.
    Name string `json:"name"`

    MediaType media.Type `json:"mediaType"`

    // Must be set to a value when there are two or more conflicting mediatype for the same resource.
    Path string `json:"path"`

    // The base output file name used when not using "ugly URLs", defaults to "index".
    BaseName string `json:"baseName"`

    // The value to use for rel links
    //
    // See https://www.w3schools.com/tags/att_link_rel.asp
    //
    // AMP has a special requirement in this department, see:
    // https://www.ampproject.org/docs/guides/deploy/discovery
    // I.e.:
    // <link rel="amphtml" href="https://www.example.com/url/to/amp/document.html">
    Rel string `json:"rel"`

    // The protocol to use, i.e. "webcal://". Defaults to the protocol of the baseURL.
    Protocol string `json:"protocol"`

    // IsPlainText decides whether to use text/template or html/template
    // as template parser.
    IsPlainText bool `json:"isPlainText"`

    // IsHTML returns whether this format is int the HTML family. This includes
    // HTML, AMP etc. This is used to decide when to create alias redirects etc.
    IsHTML bool `json:"isHTML"`

    // Enable to ignore the global uglyURLs setting.
    NoUgly bool `json:"noUgly"`

    // Enable if it doesn't make sense to include this format in an alternative
    // format listing, CSS being one good example.
    // Note that we use the term "alternative" and not "alternate" here, as it
    // does not necessarily replace the other format, it is an alternative representation.
    NotAlternative bool `json:"notAlternative"`

    // Setting this will make this output format control the value of
    // .Permalink and .RelPermalink for a rendered Page.
    // If not set, these values will point to the main (first) output format
    // configured. That is probably the behaviour you want in most situations,
    // as you probably don't want to link back to the RSS version of a page, as an
    // example. AMP would, however, be a good example of an output format where this
    // behaviour is wanted.
    Permalinkable bool `json:"permalinkable"`

    // Setting this to a non-zero value will be used as the first sort criteria.
    Weight int `json:"weight"`
}

Format represents an output representation, usually to a file on disk.

func (Format) BaseFilename Uses

func (f Format) BaseFilename() string

BaseFilename returns the base filename of f including an extension (ie. "index.xml").

func (Format) MarshalJSON Uses

func (f Format) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of f.

type Formats Uses

type Formats []Format

Formats is a slice of Format.

func DecodeFormats Uses

func DecodeFormats(mediaTypes media.Types, maps ...map[string]interface{}) (Formats, error)

DecodeFormats takes a list of output format configurations and merges those, in the order given, with the Hugo defaults as the last resort.

func (Formats) FromFilename Uses

func (formats Formats) FromFilename(filename string) (f Format, found bool)

FromFilename gets a Format given a filename.

func (Formats) GetByName Uses

func (formats Formats) GetByName(name string) (f Format, found bool)

GetByName gets a format by its identifier name.

func (Formats) GetByNames Uses

func (formats Formats) GetByNames(names ...string) (Formats, error)

GetByNames gets a list of formats given a list of identifiers.

func (Formats) GetBySuffix Uses

func (formats Formats) GetBySuffix(suffix string) (f Format, found bool)

GetBySuffix gets a output format 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 (Formats) Len Uses

func (formats Formats) Len() int

func (Formats) Less Uses

func (formats Formats) Less(i, j int) bool

func (Formats) Swap Uses

func (formats Formats) Swap(i, j int)

type LayoutDescriptor Uses

type LayoutDescriptor struct {
    Type    string
    Section string
    Kind    string
    Lang    string
    Layout  string
    // LayoutOverride indicates what we should only look for the above layout.
    LayoutOverride bool

    RenderingHook bool
    Baseof        bool
}

LayoutDescriptor describes how a layout should be chosen. This is typically built from a Page.

type LayoutHandler Uses

type LayoutHandler struct {
    // contains filtered or unexported fields
}

LayoutHandler calculates the layout template to use to render a given output type.

func NewLayoutHandler Uses

func NewLayoutHandler() *LayoutHandler

NewLayoutHandler creates a new LayoutHandler.

func (*LayoutHandler) For Uses

func (l *LayoutHandler) For(d LayoutDescriptor, f Format) ([]string, error)

For returns a layout for the given LayoutDescriptor and options. Layouts are rendered and cached internally.

Package output imports 10 packages (graph) and is imported by 201 packages. Updated 2020-06-18. Refresh now. Tools for package owners.