output

package
v0.133.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: Apache-2.0 Imports: 11 Imported by: 147

Documentation

Overview

Package output contains Output Format types and functions.

Index

Constants

This section is empty.

Variables

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

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

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

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

		Weight: 10,
	}

	MarkdownFormat = Format{
		Name:        "markdown",
		MediaType:   media.Builtin.MarkdownType,
		BaseName:    "index",
		Rel:         "alternate",
		IsPlainText: true,
	}

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

	WebAppManifestFormat = Format{
		Name:           "webappmanifest",
		MediaType:      media.Builtin.WebAppManifestType,
		BaseName:       "manifest",
		IsPlainText:    true,
		NotAlternative: true,
		Rel:            "manifest",
	}

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

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

	SitemapFormat = Format{
		Name:      "sitemap",
		MediaType: media.Builtin.XMLType,
		BaseName:  "sitemap",
		Ugly:      true,
		Rel:       "sitemap",
	}

	SitemapIndexFormat = Format{
		Name:      "sitemapindex",
		MediaType: media.Builtin.XMLType,
		BaseName:  "sitemap",
		Ugly:      true,
		Root:      true,
		Rel:       "sitemap",
	}

	HTTPStatusHTMLFormat = Format{
		Name:           "httpstatus",
		MediaType:      media.Builtin.HTMLType,
		NotAlternative: true,
		Ugly:           true,
		IsHTML:         true,
		Permalinkable:  true,
	}
)

Built-in output formats.

DefaultFormats contains the default output formats supported by Hugo.

Functions

func DecodeConfig added in v0.112.0

func DecodeConfig(mediaTypes media.Types, in any) (*config.ConfigNamespace[map[string]OutputFormatConfig, Formats], error)

Types

type Format

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.
	// <docsmeta>{ "identifiers": ["html", "rss"] }</docsmeta>
	Name string `json:"-"`

	MediaType media.Type `json:"-"`

	// 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.
	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 to override the global uglyURLs setting.
	Ugly bool `json:"ugly"`

	// 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"`

	// Eneable if this is a resource which path always starts at the root,
	// e.g. /robots.txt.
	Root bool `json:"root"`

	// 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 behavior 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
	// behavior 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. <docsmeta>{ "name": "OutputFormat" }</docsmeta>

func (Format) BaseFilename

func (f Format) BaseFilename() string

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

func (Format) IsZero added in v0.123.0

func (f Format) IsZero() bool

IsZero returns true if f represents a zero value.

func (Format) MarshalJSON

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

MarshalJSON returns the JSON encoding of f. For internal use only.

type Formats

type Formats []Format

Formats is a slice of Format. <docsmeta>{ "name": "OutputFormats" }</docsmeta>

func (Formats) FromFilename

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

FromFilename gets a Format given a filename.

func (Formats) GetByName

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

GetByName gets a format by its identifier name.

func (Formats) GetByNames

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

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

func (Formats) GetBySuffix

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

func (formats Formats) Len() int

func (Formats) Less

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

func (Formats) Swap

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

type OutputFormatConfig added in v0.112.0

type OutputFormatConfig struct {
	// The MediaType string. This must be a configured media type.
	MediaType string
	Format
}

OutputFormatConfig configures a single output format.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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