hugolib

package
v0.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: Apache-2.0 Imports: 81 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConfigFile = errors.New("Unable to locate config file or config directory. Perhaps you need to create a new site.\n       Run `hugo help new` for details.\n")

Functions

func LoadConfig

func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provider) error) (*viper.Viper, []string, error)

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

func LoadConfigDefault

func LoadConfigDefault(fs afero.Fs) (*viper.Viper, error)

LoadConfigDefault is a convenience method to load the default "config.toml" config.

Types

type BuildCfg

type BuildCfg struct {
	// Reset site state before build. Use to force full rebuilds.
	ResetState bool
	// If set, we re-create the sites from the given configuration before a build.
	// This is needed if new languages are added.
	NewConfig config.Provider
	// Skip rendering. Useful for testing.
	SkipRender bool

	// This is a partial re-render of some selected pages. This means
	// we should skip most of the processing.
	PartialReRender bool

	// Set in server mode when the last build failed for some reason.
	ErrRecovery bool

	// Recently visited URLs. This is used for partial re-rendering.
	RecentlyVisited map[string]bool
	// contains filtered or unexported fields
}

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

type ConfigSourceDescriptor

type ConfigSourceDescriptor struct {
	Fs     afero.Fs
	Logger loggers.Logger

	// Path to the config file to use, e.g. /my/project/config.toml
	Filename string

	// The path to the directory to look for configuration. Is used if Filename is not
	// set or if it is set to a relative filename.
	Path string

	// The project's working dir. Is used to look for additional theme config.
	WorkingDir string

	// The (optional) directory for additional configuration files.
	AbsConfigDir string

	// production, development
	Environment string

	// Defaults to os.Environ if not set.
	Environ []string
}

ConfigSourceDescriptor describes where to find the config (e.g. config.toml etc.).

type HugoSites

type HugoSites struct {
	Sites []*Site

	*deps.Deps

	// Keeps track of bundle directories and symlinks to enable partial rebuilding.
	ContentChanges *contentChangeMap
	// contains filtered or unexported fields
}

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

func NewHugoSites

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) Data

func (h *HugoSites) Data() map[string]interface{}

func (HugoSites) Done

func (f HugoSites) Done() <-chan bool

func (HugoSites) FatalError

func (f HugoSites) FatalError(err error)

FatalError error is used in some rare situations where it does not make sense to continue processing, to abort as soon as possible and log the error.

func (*HugoSites) GC

func (h *HugoSites) GC() (int, error)

GC requires a build first and must run on it's own. It is not thread safe.

func (*HugoSites) GetContentPage

func (h *HugoSites) GetContentPage(filename string) page.Page

GetContentPage finds a Page with content given the absolute filename. Returns nil if none found.

func (HugoSites) IncrContentRender

func (h HugoSites) IncrContentRender()

func (*HugoSites) IsMultihost

func (h *HugoSites) IsMultihost() bool

func (*HugoSites) LanguageSet

func (h *HugoSites) LanguageSet() map[string]int

TODO(bep) consolidate

func (*HugoSites) NumLogErrors

func (h *HugoSites) NumLogErrors() int

func (*HugoSites) Pages

func (h *HugoSites) Pages() page.Pages

Pages returns all pages for all sites.

func (*HugoSites) PrintProcessingStats

func (h *HugoSites) PrintProcessingStats(w io.Writer)

type Multilingual

type Multilingual struct {
	Languages langs.Languages

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

Multilingual manages the all languages used in a multilingual site.

func (*Multilingual) Language

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

Language returns the Language associated with the given string.

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
	page.WeightedPages
}

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

func (OrderedTaxonomyEntry) Count

func (ie OrderedTaxonomyEntry) Count() int

Count returns the count the pages in this taxonomy.

func (OrderedTaxonomyEntry) Pages

func (ie OrderedTaxonomyEntry) Pages() page.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 PageCollections

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

PageCollections contains the page collections for a site.

func (*PageCollections) AllPages

func (c *PageCollections) AllPages() page.Pages

AllPages returns all pages for all languages.

func (*PageCollections) AllRegularPages

func (c *PageCollections) AllRegularPages() page.Pages

AllPages returns all regular pages for all languages.

func (*PageCollections) Pages

func (c *PageCollections) Pages() page.Pages

Pages returns all pages. This is for the current language only.

func (*PageCollections) RegularPages

func (c *PageCollections) RegularPages() page.Pages

RegularPages returns all the regular pages. This is for the current language only.

type Permalinker

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

Permalinker provides permalinks of both the relative and absolute kind.

type ShortcodeWithPage

type ShortcodeWithPage struct {
	Params        interface{}
	Inner         template.HTML
	Page          page.Page
	Parent        *ShortcodeWithPage
	Name          string
	IsNamedParams bool

	// Zero-based ordinal in relation to its parent. If the parent is the page itself,
	// this ordinal will represent the position of this shortcode in the page content.
	Ordinal int
	// 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) Position

func (scp *ShortcodeWithPage) Position() text.Position

Position returns this shortcode's detailed position. Note that this information may be expensive to calculate, so only use this in error situations.

func (*ShortcodeWithPage) Ref

func (scp *ShortcodeWithPage) Ref(args map[string]interface{}) (string, error)

Ref is a shortcut to the Ref method on Page. It passes itself as a context to get better error messages.

func (*ShortcodeWithPage) RelRef

func (scp *ShortcodeWithPage) RelRef(args map[string]interface{}) (string, error)

RelRef is a shortcut to the RelRef method on Page. It passes itself as a context to get better error messages.

func (*ShortcodeWithPage) Scratch

func (scp *ShortcodeWithPage) Scratch() *maps.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() page.Site

Site returns information about the current site.

type Site

type Site struct {
	*PageCollections

	Sections Taxonomy
	Info     *SiteInfo

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

func NewEnglishSite(withTemplate ...func(templ tpl.TemplateManager) 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. TODO(bep) test refactor -- remove

func NewSite

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

func NewSiteDefaultLang(withTemplate ...func(templ tpl.TemplateManager) 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. TODO(bep) test refactor -- remove

func NewSiteForCfg

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) GetRelatedDocsHandler

func (s *Site) GetRelatedDocsHandler() *page.RelatedDocsHandler

func (*Site) Initialise

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

func (*Site) Language

func (s *Site) Language() *langs.Language

func (*Site) Menus

func (s *Site) Menus() navigation.Menus

func (*Site) RegisterMediaTypes

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) Taxonomies

func (s *Site) Taxonomies() TaxonomyList

type SiteConfig

type SiteConfig struct {
	// This contains all privacy related settings that can be used to
	// make the YouTube template etc. GDPR compliant.
	Privacy privacy.Config

	// Services contains config for services such as Google Analytics etc.
	Services services.Config
}

SiteConfig represents the config in .Site.Config.

type SiteInfo

type SiteInfo struct {
	Authors page.AuthorList
	Social  SiteSocial

	RSSLink      string
	Author       map[string]interface{}
	LanguageCode string
	Copyright    string

	LanguagePrefix string
	Languages      langs.Languages

	BuildDrafts bool
	// contains filtered or unexported fields
}

func (*SiteInfo) AllPages

func (s *SiteInfo) AllPages() page.Pages

func (*SiteInfo) AllRegularPages

func (s *SiteInfo) AllRegularPages() page.Pages

func (*SiteInfo) BaseURL

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

func (*SiteInfo) Config

func (s *SiteInfo) Config() SiteConfig

func (*SiteInfo) Data

func (s *SiteInfo) Data() map[string]interface{}

func (*SiteInfo) DisqusShortname

func (s *SiteInfo) DisqusShortname() string

DisqusShortname is kept here for historic reasons.

func (*SiteInfo) GetPage

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

GetPage looks up a page of a given type for the given ref. In Hugo <= 0.44 you had to add Page Kind (section, home) etc. as the first argument and then either a unix styled path (with or without a leading slash)) or path elements separated. When we now remove the Kind from this API, we need to make the transition as painless as possible for existing sites. Most sites will use {{ .Site.GetPage "section" "my/section" }}, i.e. 2 arguments, so we test for that.

func (*SiteInfo) GetPageWithTemplateInfo

func (s *SiteInfo) GetPageWithTemplateInfo(info tpl.Info, ref ...string) (page.Page, error)

func (*SiteInfo) GoogleAnalytics

func (s *SiteInfo) GoogleAnalytics() string

GoogleAnalytics is kept here for historic reasons.

func (*SiteInfo) Home

func (s *SiteInfo) Home() (page.Page, error)

Home is a shortcut to the home page, equivalent to .Site.GetPage "home".

func (*SiteInfo) HomeAbsURL

func (s *SiteInfo) HomeAbsURL() string

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

func (*SiteInfo) Hugo

func (s *SiteInfo) Hugo() neohugo.Info

func (*SiteInfo) IsMultiLingual

func (s *SiteInfo) IsMultiLingual() bool

func (*SiteInfo) IsServer

func (s *SiteInfo) IsServer() bool

func (*SiteInfo) Language

func (s *SiteInfo) Language() *langs.Language

func (*SiteInfo) LastChange

func (s *SiteInfo) LastChange() time.Time

func (*SiteInfo) Menus

func (s *SiteInfo) Menus() navigation.Menus

func (*SiteInfo) Pages

func (s *SiteInfo) Pages() page.Pages

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.

func (*SiteInfo) Params

func (s *SiteInfo) Params() maps.Params
func (s *SiteInfo) Permalinks() map[string]string

func (*SiteInfo) RegularPages

func (s *SiteInfo) RegularPages() page.Pages

func (*SiteInfo) Sections

func (s *SiteInfo) Sections() page.Pages

Sections returns the top level sections.

func (*SiteInfo) ServerPort

func (s *SiteInfo) ServerPort() int

ServerPort returns the port part of the BaseURL, 0 if none found.

func (*SiteInfo) Site

func (s *SiteInfo) Site() page.Site

func (*SiteInfo) SitemapAbsURL

func (s *SiteInfo) SitemapAbsURL() string

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

func (*SiteInfo) Sites

func (s *SiteInfo) Sites() page.Sites

Sites is a convenience method to get all the Hugo sites/languages configured.

func (*SiteInfo) String

func (s *SiteInfo) String() string

func (*SiteInfo) Taxonomies

func (s *SiteInfo) Taxonomies() interface{}

TODO(bep) type

func (*SiteInfo) Title

func (s *SiteInfo) Title() 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 pinterest instagram youtube linkedin

type Taxonomy

type Taxonomy map[string]page.WeightedPages

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

TagTaxonomy['technology'] = page.WeightedPages
TagTaxonomy['go']  =  page.WeightedPages

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) page.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

Directories

Path Synopsis
Package filesystems provides the fine grained file systems used by Hugo.
Package filesystems provides the fine grained file systems used by Hugo.

Jump to

Keyboard shortcuts

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