hugolib

package
v0.20.6 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2017 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindPage = "page"

	// The rest are node types; home page, sections etc.
	KindHome         = "home"
	KindSection      = "section"
	KindTaxonomy     = "taxonomy"
	KindTaxonomyTerm = "taxonomyTerm"
)

Variables

View Source
var (
	// CommitHash contains the current Git revision. Use make to build to make
	// sure this gets set.
	CommitHash string

	// BuildDate contains the date of the current build.
	BuildDate string
)
View Source
var ErrHasDraftAndPublished = errors.New("both draft and published parameters were found in page's frontmatter")

Functions

func HandlerMatch

func HandlerMatch(h Handler, ext string) bool

func LoadConfig added in v0.20.1

func LoadConfig(fs afero.Fs, relativeSourcePath, configFilename string) (*viper.Viper, error)

LoadConfig loads Hugo configuration into a new Viper and then adds a set of defaults.

func RegisterHandler

func RegisterHandler(h Handler)

Types

type Author

type Author struct {
	GivenName   string
	FamilyName  string
	DisplayName string
	Thumbnail   string
	Image       string
	ShortBio    string
	LongBio     string
	Email       string
	Social      AuthorSocial
}

Author contains details about the author of a page.

type AuthorList

type AuthorList map[string]Author

AuthorList is a list of all authors and their metadata.

type AuthorSocial

type AuthorSocial map[string]string

AuthorSocial is a place to put social details per author. These are the standard keys that themes will expect to have available, but can be expanded to any others on a per site basis - website - github - facebook - twitter - googleplus - pinterest - instagram - youtube - linkedin - skype

type BuildCfg

type BuildCfg struct {
	// Whether we are in watch (server) mode
	Watching bool
	// Print build stats at the end of a build
	PrintStats bool
	// Reset site state before build. Use to force full rebuilds.
	ResetState bool
	// Re-creates the sites from configuration before a build.
	// This is needed if new languages are added.
	CreateSitesFromConfig bool
	// Skip rendering. Useful for testing.
	SkipRender bool
	// contains filtered or unexported fields
}

BuildCfg holds build options used to, as an example, skip the render step.

type Handle

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

func (Handle) Extensions

func (h Handle) Extensions() []string

type HandleResults

type HandleResults chan<- HandledResult

type HandledResult

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

func (HandledResult) Error

func (h HandledResult) Error() string

HandledResult is an error

func (HandledResult) Page

func (h HandledResult) Page() *Page

func (HandledResult) String

func (h HandledResult) String() string

type Handler

type Handler interface {
	FileConvert(*source.File, *Site) HandledResult
	PageConvert(*Page) HandledResult
	Read(*source.File, *Site) HandledResult
	Extensions() []string
}

func FindHandler

func FindHandler(ext string) Handler

func Handlers

func Handlers() []Handler

type HugoInfo

type HugoInfo struct {
	Version    string
	Generator  template.HTML
	CommitHash string
	BuildDate  string
}

HugoInfo contains information about the current Hugo environment

type HugoSites

type HugoSites struct {
	Sites []*Site

	*deps.Deps
	// contains filtered or unexported fields
}

HugoSites represents the sites to build. Each site represents a language.

func NewHugoSites added in v0.20.1

func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error)

NewHugoSites creates HugoSites from the given config.

func (*HugoSites) Build

func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error

Build builds all sites. If filesystem events are provided, this is considered to be a potential partial rebuild.

func (*HugoSites) Pages

func (h *HugoSites) Pages() Pages

Pages returns all pages for all sites.

type Image

type Image struct {

	// The URL of the image. In some cases, the image URL may not be on the
	// same domain as your main site. This is fine, as long as both domains
	// are verified in Webmaster Tools. If, for example, you use a
	// content delivery network (CDN) to host your images, make sure that the
	// hosting site is verified in Webmaster Tools OR that you submit your
	// sitemap using robots.txt. In addition, make sure that your robots.txt
	// file doesn’t disallow the crawling of any content you want indexed.
	URL     string
	Title   string
	Caption string
	AltText string

	// The geographic location of the image. For example,
	// <image:geo_location>Limerick, Ireland</image:geo_location>.
	GeoLocation string

	// A URL to the license of the image.
	License string
}

An Image contains metadata for images + image sitemaps https://support.google.com/webmasters/answer/178636?hl=en

type Menu []*MenuEntry

Menu is a collection of menu entries.

func (m Menu) ByName() Menu

ByName sorts the menu by the name defined in the menu configuration.

func (m Menu) ByWeight() Menu

ByWeight sorts the menu by the weight defined in the menu configuration.

func (m Menu) Limit(n int) Menu

Limit limits the returned menu to n entries.

func (m Menu) Reverse() Menu

Reverse reverses the order of the menu entries.

func (m Menu) Sort() Menu

Sort sorts the menu by weight, name and then by identifier.

type MenuEntry struct {
	URL        string
	Name       string
	Menu       string
	Identifier string
	Pre        template.HTML
	Post       template.HTML
	Weight     int
	Parent     string
	Children   Menu
}

MenuEntry represents a menu item defined in either Page front matter or in the site config.

func (m *MenuEntry) HasChildren() bool

HasChildren returns whether this menu item has any children.

func (m *MenuEntry) IsEqual(inme *MenuEntry) bool

IsEqual returns whether the two menu entries represents the same menu entry.

func (m *MenuEntry) IsSameResource(inme *MenuEntry) bool

IsSameResource returns whether the two menu entries points to the same resource (URL).

func (m *MenuEntry) KeyName() string

KeyName returns the key used to identify this menu entry.

type Menus map[string]*Menu

Menus is a dictionary of menus.

type MetaHandle

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

func NewMetaHandler

func NewMetaHandler(in string) *MetaHandle

func (*MetaHandle) Convert

func (mh *MetaHandle) Convert(i interface{}, s *Site, results HandleResults)

func (*MetaHandle) Handler

func (mh *MetaHandle) Handler() Handler

func (*MetaHandle) Read

func (mh *MetaHandle) Read(f *source.File, s *Site, results HandleResults)

type MetaHandler

type MetaHandler interface {
	// Read the Files in and register
	Read(*source.File, *Site, HandleResults)

	// Generic Convert Function with coordination
	Convert(interface{}, *Site, HandleResults)

	Handle() Handler
}

type Multilingual

type Multilingual struct {
	Languages helpers.Languages

	DefaultLang *helpers.Language
	// contains filtered or unexported fields
}

func (*Multilingual) Language

func (ml *Multilingual) Language(lang string) *helpers.Language

type OrderedTaxonomy

type OrderedTaxonomy []OrderedTaxonomyEntry

OrderedTaxonomy is another representation of an Taxonomy using an array rather than a map. Important because you can't order a map.

func (OrderedTaxonomy) Reverse

func (t OrderedTaxonomy) Reverse() OrderedTaxonomy

Reverse reverses the order of the entries in this taxonomy.

type OrderedTaxonomyEntry

type OrderedTaxonomyEntry struct {
	Name          string
	WeightedPages WeightedPages
}

OrderedTaxonomyEntry is similar to an element of a Taxonomy, but with the key embedded (as name) e.g: {Name: Technology, WeightedPages: Taxonomyedpages}

func (OrderedTaxonomyEntry) Count

func (ie OrderedTaxonomyEntry) Count() int

Count returns the count the pages in this taxonomy.

func (OrderedTaxonomyEntry) Pages

func (ie OrderedTaxonomyEntry) Pages() Pages

Pages returns the Pages for this taxonomy.

func (OrderedTaxonomyEntry) Term

func (ie OrderedTaxonomyEntry) Term() string

Term returns the name given to this taxonomy.

type OutputFormat added in v0.20.1

type OutputFormat struct {
	// Rel constains a value that can be used to construct a rel link.
	// This is value is fetched from the output format definition.
	// Note that for pages with only one output format,
	// this method will always return "canonical".
	// As an example, the AMP output format will, by default, return "amphtml".
	//
	// See:
	// https://www.ampproject.org/docs/guides/deploy/discovery
	//
	// Most other output formats will have "alternate" as value for this.
	Rel string
	// contains filtered or unexported fields
}

And OutputFormat links to a representation of a resource.

func (OutputFormat) MediaType added in v0.20.1

func (o OutputFormat) MediaType() media.Type

MediaType returns this OutputFormat's MediaType (MIME type).

func (OutputFormat) Name added in v0.20.1

func (o OutputFormat) Name() string

Name returns this OutputFormat's name, i.e. HTML, AMP, JSON etc.

func (o *OutputFormat) Permalink() string

Permalink returns the absolute permalink to this output format.

func (o *OutputFormat) RelPermalink() string

Permalink returns the relative permalink to this output format.

type OutputFormats added in v0.20.1

type OutputFormats []*OutputFormat

OutputFormats holds a list of the relevant output formats for a given resource.

func (OutputFormats) Get added in v0.20.1

func (o OutputFormats) Get(name string) *OutputFormat

Get gets a OutputFormat given its name, i.e. json, html etc. It returns nil if not found.

type Page

type Page struct {

	// Kind is the discriminator that identifies the different page types
	// in the different page collections. This can, as an example, be used
	// to to filter regular pages, find sections etc.
	// Kind will, for the pages available to the templates, be one of:
	// page, home, section, taxonomy and taxonomyTerm.
	// It is of string type to make it easy to reason about in
	// the templates.
	Kind string

	// Since Hugo 0.18 we got rid of the Node type. So now all pages are ...
	// pages (regular pages, home page, sections etc.).
	// Sections etc. will have child pages. These were earlier placed in .Data.Pages,
	// but can now be more intuitively also be fetched directly from .Pages.
	// This collection will be nil for regular pages.
	Pages Pages

	// Params contains configuration defined in the params section of page frontmatter.
	Params map[string]interface{}

	// Content sections
	Content         template.HTML
	Summary         template.HTML
	TableOfContents template.HTML

	Aliases []string

	Images []Image
	Videos []Video

	Truncated bool
	Draft     bool
	Status    string

	PublishDate time.Time
	ExpiryDate  time.Time

	// PageMeta contains page stats such as word count etc.
	PageMeta

	// Markup contains the markup type for the content.
	Markup string

	Layout string

	Source

	Position `json:"-"`

	GitInfo *gitmap.GitInfo

	Site *SiteInfo `json:"-"`

	Title       string
	Description string
	Keywords    []string
	Data        map[string]interface{}

	Date    time.Time
	Lastmod time.Time

	Sitemap Sitemap

	URLPath
	// contains filtered or unexported fields
}

func (*Page) AllTranslations

func (p *Page) AllTranslations() Pages

AllTranslations returns all translations, including the current Page.

func (*Page) AlternativeOutputFormats added in v0.20.1

func (p *Page) AlternativeOutputFormats() (OutputFormats, error)

AlternativeOutputFormats is only available on the top level rendering entry point, and not inside range loops on the Page collections. This method is just here to inform users of that restriction.

func (*Page) Author

func (p *Page) Author() Author

func (*Page) Authors

func (p *Page) Authors() AuthorList

func (*Page) Extension

func (p *Page) Extension() string

func (*Page) FullFilePath

func (p *Page) FullFilePath() string

func (*Page) FuzzyWordCount

func (p *Page) FuzzyWordCount() int

func (*Page) GetParam

func (p *Page) GetParam(key string) interface{}

func (*Page) HasMenuCurrent

func (p *Page) HasMenuCurrent(menuID string, me *MenuEntry) bool

func (*Page) Hugo

func (p *Page) Hugo() *HugoInfo

func (*Page) IsDraft

func (p *Page) IsDraft() bool

func (*Page) IsExpired

func (p *Page) IsExpired() bool

func (*Page) IsFuture

func (p *Page) IsFuture() bool

func (*Page) IsHome

func (p *Page) IsHome() bool

IsHome returns whether this is the home page.

func (*Page) IsMenuCurrent

func (p *Page) IsMenuCurrent(menuID string, inme *MenuEntry) bool

func (*Page) IsNode

func (p *Page) IsNode() bool

IsNode returns whether this is an item of one of the list types in Hugo, i.e. not a regular content page.

func (*Page) IsPage

func (p *Page) IsPage() bool

IsPage returns whether this is a regular content page.

func (*Page) IsRenderable

func (p *Page) IsRenderable() bool

func (*Page) IsTranslated

func (p *Page) IsTranslated() bool

IsTranslated returns whether this content file is translated to other language(s).

func (*Page) Lang

func (p *Page) Lang() string

func (*Page) Language

func (p *Page) Language() *helpers.Language

func (*Page) LanguagePrefix

func (p *Page) LanguagePrefix() string

func (*Page) LinkTitle

func (p *Page) LinkTitle() string

func (*Page) Menus

func (p *Page) Menus() PageMenus

func (*Page) Now

func (p *Page) Now() time.Time

func (*Page) OutputFormats added in v0.20.1

func (p *Page) OutputFormats() OutputFormats

OutputFormats gives the output formats for this Page.

func (*Page) Paginate

func (p *Page) Paginate(seq interface{}, options ...interface{}) (*Pager, error)

Paginate invokes this Page's main output's Paginate method.

func (*Page) Paginator

func (p *Page) Paginator(options ...interface{}) (*Pager, error)

Paginator get this Page's main output's paginator.

func (*Page) Param

func (p *Page) Param(key interface{}) (interface{}, error)

Param is a convenience method to do lookups in Page's and Site's Params map, in that order.

This method is also implemented on Node and SiteInfo.

func (p *Page) Permalink() string

Permalink returns the absolute URL to this Page.

func (*Page) Plain

func (p *Page) Plain() string

func (*Page) PlainWords

func (p *Page) PlainWords() []string

func (*Page) ProcessShortcodes

func (p *Page) ProcessShortcodes()
func (p *Page) RSSLink() template.URL

func (*Page) RawContent

func (p *Page) RawContent() string

func (*Page) ReadFrom

func (p *Page) ReadFrom(buf io.Reader) (int64, error)

func (*Page) ReadingTime

func (p *Page) ReadingTime() int

func (*Page) Ref

func (p *Page) Ref(refs ...string) (string, error)
func (p *Page) RelPermalink() string

RelPermalink gets a URL to the resource relative to the host.

func (*Page) RelRef

func (p *Page) RelRef(refs ...string) (string, error)

func (*Page) Render

func (p *Page) Render(layout ...string) template.HTML

func (*Page) SafeSaveSourceAs

func (p *Page) SafeSaveSourceAs(path string) error

func (*Page) SaveSource

func (p *Page) SaveSource() error

func (*Page) SaveSourceAs

func (p *Page) SaveSourceAs(path string) error

func (*Page) Scratch

func (p *Page) Scratch() *Scratch

Scratch returns the writable context associated with this Page.

func (*Page) Section

func (p *Page) Section() string

func (*Page) SetSourceContent

func (p *Page) SetSourceContent(content []byte)

func (*Page) SetSourceMetaData

func (p *Page) SetSourceMetaData(in interface{}, mark rune) (err error)

func (*Page) String

func (p *Page) String() string

func (*Page) TargetPath

func (p *Page) TargetPath() (outfile string)

func (*Page) Translations

func (p *Page) Translations() Pages

Translations returns the translations excluding the current Page.

func (*Page) Type

func (p *Page) Type() string

func (*Page) URL

func (p *Page) URL() string

func (*Page) UniqueID

func (p *Page) UniqueID() string

func (*Page) WordCount

func (p *Page) WordCount() int

type PageCollections

type PageCollections struct {
	// Includes only pages of all types, and only pages in the current language.
	Pages Pages

	// Includes all pages in all languages, including the current one.
	// Includes pages of all types.
	AllPages Pages

	// A convenience cache for the regular pages.
	// This is for the current language only.
	RegularPages Pages

	// A convenience cache for the all the regular pages.
	AllRegularPages Pages
	// contains filtered or unexported fields
}

PageCollections contains the page collections for a site.

type PageGroup

type PageGroup struct {
	Key   interface{}
	Pages Pages
}

PageGroup represents a group of pages, grouped by the key. The key is typically a year or similar.

type PageMenus map[string]*MenuEntry

PageMenus is a dictionary of menus defined in the Pages.

type PageMeta

type PageMeta struct {
	Weight int
	// contains filtered or unexported fields
}

type PageOutput added in v0.20.1

type PageOutput struct {
	*Page
	// contains filtered or unexported fields
}

PageOutput represents one of potentially many output formats of a given Page.

func (*PageOutput) AlternativeOutputFormats added in v0.20.1

func (p *PageOutput) AlternativeOutputFormats() (OutputFormats, error)

OutputFormats gives the alternative output formats for this PageOutput. 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.

func (*PageOutput) Paginate added in v0.20.1

func (p *PageOutput) Paginate(seq interface{}, options ...interface{}) (*Pager, error)

Paginate gets this PageOutput's paginator if it's already created. If it's not, one will be created with the qiven sequence. Note that repeated calls will return the same result, even if the sequence is different.

func (*PageOutput) Paginator added in v0.20.1

func (p *PageOutput) Paginator(options ...interface{}) (*Pager, error)

Paginator gets this PageOutput's paginator if it's already created. If it's not, one will be created with all pages in Data["Pages"].

func (*PageOutput) Render added in v0.20.1

func (p *PageOutput) Render(layout ...string) template.HTML

type Pager

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

Pager represents one of the elements in a paginator. The number, starting on 1, represents its place.

func (*Pager) First

func (p *Pager) First() *Pager

First returns the pager for the first page.

func (*Pager) HasNext

func (p *Pager) HasNext() bool

HasNext tests whether there are page(s) after the current.

func (*Pager) HasPrev

func (p *Pager) HasPrev() bool

HasPrev tests whether there are page(s) before the current.

func (*Pager) Last

func (p *Pager) Last() *Pager

Last returns the pager for the last page.

func (*Pager) Next

func (p *Pager) Next() *Pager

Next returns the pager for the next page.

func (*Pager) NumberOfElements

func (p *Pager) NumberOfElements() int

NumberOfElements gets the number of elements on this page.

func (*Pager) PageGroups

func (p *Pager) PageGroups() PagesGroup

PageGroups return Page groups for this page. Note: If this return non-empty result, then Pages() will return empty.

func (*Pager) PageNumber

func (p *Pager) PageNumber() int

PageNumber returns the current page's number in the pager sequence.

func (Pager) PageSize

func (p Pager) PageSize() int

PageSize returns the size of each paginator page.

func (Pager) Pagers

func (p Pager) Pagers() pagers

Pagers returns a list of pagers that can be used to build a pagination menu.

func (*Pager) Pages

func (p *Pager) Pages() Pages

Pages returns the Pages on this page. Note: If this return a non-empty result, then PageGroups() will return empty.

func (*Pager) Prev

func (p *Pager) Prev() *Pager

Prev returns the pager for the previous page.

func (Pager) String

func (p Pager) String() string

func (Pager) TotalNumberOfElements

func (p Pager) TotalNumberOfElements() int

TotalNumberOfElements returns the number of elements on all pages in this paginator.

func (Pager) TotalPages

func (p Pager) TotalPages() int

TotalPages returns the number of pages in the paginator.

func (*Pager) URL

func (p *Pager) URL() template.HTML

URL returns the URL to the current page.

type Pages

type Pages []*Page

func (Pages) ByDate

func (p Pages) ByDate() Pages

ByDate sorts the Pages by date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByExpiryDate

func (p Pages) ByExpiryDate() Pages

ByExpiryDate sorts the Pages by publish date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLanguage

func (p Pages) ByLanguage() Pages

ByLanguage sorts the Pages by the language's Weight.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLastmod

func (p Pages) ByLastmod() Pages

ByLastmod sorts the Pages by the last modification date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLength

func (p Pages) ByLength() Pages

ByLength sorts the Pages by length and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByLinkTitle

func (p Pages) ByLinkTitle() Pages

ByLinkTitle sorts the Pages by link title and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByParam added in v0.20.1

func (p Pages) ByParam(paramsKey interface{}) Pages

func (Pages) ByPublishDate

func (p Pages) ByPublishDate() Pages

ByPublishDate sorts the Pages by publish date and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByTitle

func (p Pages) ByTitle() Pages

ByTitle sorts the Pages by title and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) ByWeight

func (p Pages) ByWeight() Pages

ByWeight sorts the Pages by weight and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) FindPagePos

func (ps Pages) FindPagePos(page *Page) int

FindPagePos Given a page, it will find the position in Pages will return -1 if not found

func (Pages) FindPagePosByFilePath

func (ps Pages) FindPagePosByFilePath(inPath string) int

func (Pages) GroupBy

func (p Pages) GroupBy(key string, order ...string) (PagesGroup, error)

GroupBy groups by the value in the given field or method name and with the given order. Valid values for order is asc, desc, rev and reverse.

func (Pages) GroupByDate

func (p Pages) GroupByDate(format string, order ...string) (PagesGroup, error)

GroupByDate groups by the given page's Date value in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) GroupByExpiryDate

func (p Pages) GroupByExpiryDate(format string, order ...string) (PagesGroup, error)

GroupByExpiryDate groups by the given page's ExpireDate value in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) GroupByParam

func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error)

GroupByParam groups by the given page parameter key's value and with the given order. Valid values for order is asc, desc, rev and reverse.

func (Pages) GroupByParamDate

func (p Pages) GroupByParamDate(key string, format string, order ...string) (PagesGroup, error)

GroupByParamDate groups by a date set as a param on the page in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) GroupByPublishDate

func (p Pages) GroupByPublishDate(format string, order ...string) (PagesGroup, error)

GroupByPublishDate groups by the given page's PublishDate value in the given format and with the given order. Valid values for order is asc, desc, rev and reverse. For valid format strings, see https://golang.org/pkg/time/#Time.Format

func (Pages) Len

func (p Pages) Len() int

Len returns the number of pages in the list.

func (Pages) Limit

func (p Pages) Limit(n int) Pages

Limit limits the number of pages returned to n.

func (Pages) Next

func (p Pages) Next(cur *Page) *Page

Next returns the next page reletive to the given page.

func (Pages) Prev

func (p Pages) Prev(cur *Page) *Page

Prev returns the previous page reletive to the given page.

func (Pages) Reverse

func (p Pages) Reverse() Pages

Reverse reverses the order in Pages and returns a copy.

Adjacent invocations on the same receiver will return a cached result.

This may safely be executed in parallel.

func (Pages) Sort

func (p Pages) Sort()

Sort sorts the pages by the default sort order defined: Order by Weight, Date, LinkTitle and then full file path.

func (Pages) String

func (ps Pages) String() string

type PagesGroup

type PagesGroup []PageGroup

PagesGroup represents a list of page groups. This is what you get when doing page grouping in the templates.

func (PagesGroup) Len

func (psg PagesGroup) Len() int

Len returns the number of pages in the page group.

func (PagesGroup) Reverse

func (p PagesGroup) Reverse() PagesGroup

Reverse reverses the order of this list of page groups.

type PermalinkOverrides

type PermalinkOverrides map[string]pathPattern

PermalinkOverrides maps a section name to a PathPattern

type Permalinker added in v0.20.1

type Permalinker interface {
	Permalink() string
	RelPermalink() string
}

Permalinker provides permalinks of both the relative and absolute kind.

type Position

type Position struct {
	Prev          *Page
	Next          *Page
	PrevInSection *Page
	NextInSection *Page
}

type Scratch

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

Scratch is a writable context used for stateful operations in Page/Node rendering.

func (*Scratch) Add

func (c *Scratch) Add(key string, newAddend interface{}) (string, error)

Add will, for single values, add (using the + operator) the addend to the existing addend (if found). Supports numeric values and strings.

If the first add for a key is an array or slice, then the next value(s) will be appended.

func (*Scratch) Get

func (c *Scratch) Get(key string) interface{}

Get returns a value previously set by Add or Set

func (*Scratch) GetSortedMapValues

func (c *Scratch) GetSortedMapValues(key string) interface{}

GetSortedMapValues returns a sorted map previously filled with SetInMap

func (*Scratch) Set

func (c *Scratch) Set(key string, value interface{}) string

Set stores a value with the given key in the Node context. This value can later be retrieved with Get.

func (*Scratch) SetInMap

func (c *Scratch) SetInMap(key string, mapKey string, value interface{}) string

SetInMap stores a value to a map with the given key in the Node context. This map can later be retrieved with GetSortedMapValues.

type ShortcodeWithPage

type ShortcodeWithPage struct {
	Params        interface{}
	Inner         template.HTML
	Page          *Page
	Parent        *ShortcodeWithPage
	IsNamedParams bool
	// contains filtered or unexported fields
}

ShortcodeWithPage is the "." context in a shortcode template.

func (*ShortcodeWithPage) Get

func (scp *ShortcodeWithPage) Get(key interface{}) interface{}

Get is a convenience method to look up shortcode parameters by its key.

func (*ShortcodeWithPage) Ref

func (scp *ShortcodeWithPage) Ref(ref string) (string, error)

Ref is a shortcut to the Ref method on Page.

func (*ShortcodeWithPage) RelRef

func (scp *ShortcodeWithPage) RelRef(ref string) (string, error)

RelRef is a shortcut to the RelRef method on Page.

func (*ShortcodeWithPage) Scratch

func (scp *ShortcodeWithPage) Scratch() *Scratch

Scratch returns a scratch-pad scoped for this shortcode. This can be used as a temporary storage for variables, counters etc.

func (*ShortcodeWithPage) Site

func (scp *ShortcodeWithPage) Site() *SiteInfo

Site returns information about the current site.

type Site

type Site struct {
	*PageCollections

	Files      []*source.File
	Taxonomies TaxonomyList

	Source   source.Input
	Sections Taxonomy
	Info     SiteInfo
	Menus    Menus

	Data     map[string]interface{}
	Language *helpers.Language

	// Logger etc.
	*deps.Deps `json:"-"`
	// contains filtered or unexported fields
}

Site contains all the information relevant for constructing a static site. The basic flow of information is as follows:

1. A list of Files is parsed and then converted into Pages.

  1. Pages contain sections (based on the file they were generated from), aliases and slugs (included in a pages frontmatter) which are the various targets that will get generated. There will be canonical listing. The canonical path can be overruled based on a pattern.
  1. Taxonomies are created via configuration and will present some aspect of the final page and typically a perm url.
  1. All Pages are passed through a template based on their desired layout based on numerous different elements.

5. The entire collection of files is written to disk.

func NewEnglishSite added in v0.20.1

func NewEnglishSite(withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error)

NewEnglishSite creates a new site in English language. The site will have a template system loaded and ready to use. Note: This is mainly used in single site tests.

func NewSite added in v0.20.1

func NewSite(cfg deps.DepsCfg) (*Site, error)

NewSite creates a new site with the given dependency configuration. The site will have a template system loaded and ready to use. Note: This is mainly used in single site tests.

func NewSiteDefaultLang added in v0.20.1

func NewSiteDefaultLang(withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error)

NewSiteDefaultLang creates a new site in the default language. The site will have a template system loaded and ready to use. Note: This is mainly used in single site tests.

func NewSiteForCfg added in v0.20.1

func NewSiteForCfg(cfg deps.DepsCfg) (*Site, error)

NewSiteForCfg creates a new site for the given configuration. The site will have a template system loaded and ready to use. Note: This is mainly used in single site tests.

func (*Site) Initialise

func (s *Site) Initialise() (err error)

func (*Site) NewPage added in v0.20.1

func (s *Site) NewPage(name string) (*Page, error)

func (*Site) NewPageFrom added in v0.20.1

func (s *Site) NewPageFrom(buf io.Reader, name string) (*Page, error)

func (*Site) RegisterMediaTypes added in v0.20.1

func (s *Site) RegisterMediaTypes()

RegisterMediaTypes will register the Site's media types in the mime package, so it will behave correctly with Hugo's built-in server.

func (*Site) Stats

func (s *Site) Stats()

Stats prints Hugo builds stats to the console. This is what you see after a successful hugo build.

type SiteInfo

type SiteInfo struct {
	Taxonomies TaxonomyList
	Authors    AuthorList
	Social     SiteSocial
	Sections   Taxonomy
	*PageCollections
	Files           *[]*source.File
	Menus           *Menus
	Hugo            *HugoInfo
	Title           string
	RSSLink         string
	Author          map[string]interface{}
	LanguageCode    string
	DisqusShortname string
	GoogleAnalytics string
	Copyright       string
	LastChange      time.Time
	Permalinks      PermalinkOverrides
	Params          map[string]interface{}
	BuildDrafts     bool

	Data *map[string]interface{}

	Language       *helpers.Language
	LanguagePrefix string
	Languages      helpers.Languages
	// contains filtered or unexported fields
}

func (*SiteInfo) BaseURL

func (s *SiteInfo) BaseURL() template.URL

func (*SiteInfo) GetPage

func (s *SiteInfo) GetPage(typ string, path ...string) *Page

GetPage looks up a index page of a given type in the path given. This method may support regular pages in the future, but currently it is a convenient way of getting the home page or a section from a template:

{{ with .Site.GetPage "section" "blog" }}{{ .Title }}{{ end }}

This will return nil when no page could be found.

The valid page types are: home, section, taxonomy and taxonomyTerm

func (*SiteInfo) HomeAbsURL

func (s *SiteInfo) HomeAbsURL() string

HomeAbsURL is a convenience method giving the absolute URL to the home page.

func (*SiteInfo) IsMultiLingual

func (s *SiteInfo) IsMultiLingual() bool

func (*SiteInfo) Param

func (s *SiteInfo) Param(key interface{}) (interface{}, error)

Param is a convenience method to do lookups in SiteInfo's Params map.

This method is also implemented on Page and Node.

func (*SiteInfo) Ref

func (s *SiteInfo) Ref(ref string, page *Page, options ...string) (string, error)

Ref will give an absolute URL to ref in the given Page.

func (*SiteInfo) RelRef

func (s *SiteInfo) RelRef(ref string, page *Page, options ...string) (string, error)

RelRef will give an relative URL to ref in the given Page.

func (*SiteInfo) SitemapAbsURL

func (s *SiteInfo) SitemapAbsURL() string

SitemapAbsURL is a convenience method giving the absolute URL to the sitemap.

func (s *SiteInfo) SourceRelativeLink(ref string, currentPage *Page) (string, error)

SourceRelativeLink attempts to convert any source page relative links (like [../another.md]) into absolute links

func (*SiteInfo) SourceRelativeLinkFile

func (s *SiteInfo) SourceRelativeLinkFile(ref string, currentPage *Page) (string, error)

SourceRelativeLinkFile attempts to convert any non-md source relative links (like [../another.gif]) into absolute links

func (*SiteInfo) String

func (s *SiteInfo) String() string

type SiteSocial

type SiteSocial map[string]string

SiteSocial is a place to put social details on a site level. These are the standard keys that themes will expect to have available, but can be expanded to any others on a per site basis github facebook facebook_admin twitter twitter_domain googleplus pinterest instagram youtube linkedin

type Sitemap

type Sitemap struct {
	ChangeFreq string
	Priority   float64
	Filename   string
}

Sitemap configures the sitemap to be generated.

type Source

type Source struct {
	Frontmatter []byte
	Content     []byte
	source.File
}

type Taxonomy

type Taxonomy map[string]WeightedPages

A Taxonomy is a map of keywords to a list of pages. For example

TagTaxonomy['technology'] = WeightedPages
TagTaxonomy['go']  =  WeightedPages2

func (Taxonomy) Alphabetical

func (i Taxonomy) Alphabetical() OrderedTaxonomy

Alphabetical returns an ordered taxonomy sorted by key name.

func (Taxonomy) ByCount

func (i Taxonomy) ByCount() OrderedTaxonomy

ByCount returns an ordered taxonomy sorted by # of pages per key. If taxonomies have the same # of pages, sort them alphabetical

func (Taxonomy) Count

func (i Taxonomy) Count(key string) int

Count the weighted pages for the given key.

func (Taxonomy) Get

func (i Taxonomy) Get(key string) WeightedPages

Get the weighted pages for the given key.

func (Taxonomy) TaxonomyArray

func (i Taxonomy) TaxonomyArray() OrderedTaxonomy

TaxonomyArray returns an ordered taxonomy with a non defined order.

type TaxonomyList

type TaxonomyList map[string]Taxonomy

The TaxonomyList is a list of all taxonomies and their values e.g. List['tags'] => TagTaxonomy (from above)

func (TaxonomyList) String

func (tl TaxonomyList) String() string

type Translations

type Translations map[string]*Page

Translations represent the other translations for a given page. The string here is the language code, as affected by the `post.LANG.md` filename.

type URLPath

type URLPath struct {
	URL       string
	Permalink string
	Slug      string
	Section   string
}

type Video

type Video struct {
	ThumbnailLoc         string
	Title                string
	Description          string
	ContentLoc           string
	PlayerLoc            string
	Duration             string
	ExpirationDate       string
	Rating               string
	ViewCount            string
	PublicationDate      string
	FamilyFriendly       string
	Restriction          string
	GalleryLoc           string
	Price                string
	RequiresSubscription string
	Uploader             string
	Live                 string
}

A Video contains metadata for videos + video sitemaps https://support.google.com/webmasters/answer/80471?hl=en

type WeightedPage

type WeightedPage struct {
	Weight int
	Page   *Page
}

A WeightedPage is a Page with a weight.

func (WeightedPage) String

func (w WeightedPage) String() string

type WeightedPages

type WeightedPages []WeightedPage

WeightedPages is a list of Pages with their corresponding (and relative) weight [{Weight: 30, Page: *1}, {Weight: 40, Page: *2}]

func (WeightedPages) Count

func (wp WeightedPages) Count() int

Count returns the number of pages in this weighted page set.

func (WeightedPages) Len

func (wp WeightedPages) Len() int

func (WeightedPages) Less

func (wp WeightedPages) Less(i, j int) bool

func (WeightedPages) Next

func (wp WeightedPages) Next(cur *Page) *Page

Next returns the next Page relative to the given Page in this weighted page set.

func (WeightedPages) Pages

func (wp WeightedPages) Pages() Pages

Pages returns the Pages in this weighted page set.

func (WeightedPages) Prev

func (wp WeightedPages) Prev(cur *Page) *Page

Prev returns the previous Page relative to the given Page in this weighted page set.

func (WeightedPages) Sort

func (wp WeightedPages) Sort()

Sort stable sorts this weighted page set.

func (WeightedPages) Swap

func (wp WeightedPages) Swap(i, j int)

Jump to

Keyboard shortcuts

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