hugolib

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: Apache-2.0 Imports: 89 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() *allconfig.Config

DefaultConfig returns the default configuration.

func ExampleConfig

func ExampleConfig() (*allconfig.Config, error)

ExampleConfig returns the some example configuration for documentation.

Types

type BuildCfg

type BuildCfg struct {
	// Reset site state before build. Use to force full rebuilds.
	ResetState bool
	// 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

	// Can be set to build only with a sub set of the content source.
	ContentInclusionFilter *glob.FilenameFilter

	// Set when the buildlock is already acquired (e.g. the archetype content builder).
	NoBuildLock bool
	// contains filtered or unexported fields
}

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

type ContentFactory

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

ContentFactory creates content files from archetype templates.

func NewContentFactory

func NewContentFactory(h *HugoSites) ContentFactory

NewContentFactory creates a new ContentFactory for h.

func (ContentFactory) ApplyArchetypeFilename

func (f ContentFactory) ApplyArchetypeFilename(w io.Writer, p page.Page, archetypeKind, archetypeFilename string) error

ApplyArchetypeFilename archetypeFilename to w as a template using the given Page p as the foundation for the data context.

func (ContentFactory) ApplyArchetypeTemplate

func (f ContentFactory) ApplyArchetypeTemplate(w io.Writer, p page.Page, archetypeKind, templateSource string) error

ApplyArchetypeTemplate templateSource to w as a template using the given Page p as the foundation for the data context.

func (ContentFactory) CreateContentPlaceHolder

func (f ContentFactory) CreateContentPlaceHolder(filename string, force bool) (string, error)

CreateContentPlaceHolder creates a content placeholder file inside the best matching content directory.

func (ContentFactory) SectionFromFilename

func (f ContentFactory) SectionFromFilename(filename string) (string, error)

type HugoSites

type HugoSites struct {
	Sites []*Site

	Configs *allconfig.Configs

	*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]any

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

func (h HugoSites) IncrPageRender()

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)

func (*HugoSites) ShouldSkipFileChangeEvent

func (h *HugoSites) ShouldSkipFileChangeEvent(ev fsnotify.Event) bool

ShouldSkipFileChangeEvent allows skipping filesystem event early before the build is started.

type IntegrationTestBuilder

type IntegrationTestBuilder struct {
	*qt.C

	H *HugoSites

	Cfg IntegrationTestConfig

	GCCount int
	// contains filtered or unexported fields
}

IntegrationTestBuilder is a (partial) rewrite of sitesBuilder. The main problem with the "old" one was that it was that the test data was often a little hidden, so it became hard to look at a test and determine what it should do, especially coming back to the test after a year or so.

func NewIntegrationTestBuilder

func NewIntegrationTestBuilder(conf IntegrationTestConfig) *IntegrationTestBuilder

func Test

func Test(t testing.TB, files string) *IntegrationTestBuilder

Test is a convenience method to create a new IntegrationTestBuilder from some files and run a build.

func TestRunning

func TestRunning(t testing.TB, files string) *IntegrationTestBuilder

TestRunning is a convenience method to create a new IntegrationTestBuilder from some files with Running set to true and run a build.

func (*IntegrationTestBuilder) AddFiles

func (s *IntegrationTestBuilder) AddFiles(filenameContent ...string) *IntegrationTestBuilder

func (*IntegrationTestBuilder) AssertBuildCountData

func (s *IntegrationTestBuilder) AssertBuildCountData(count int)

func (*IntegrationTestBuilder) AssertBuildCountGitInfo

func (s *IntegrationTestBuilder) AssertBuildCountGitInfo(count int)

func (*IntegrationTestBuilder) AssertBuildCountLayouts

func (s *IntegrationTestBuilder) AssertBuildCountLayouts(count int)

func (*IntegrationTestBuilder) AssertBuildCountTranslations

func (s *IntegrationTestBuilder) AssertBuildCountTranslations(count int)

func (*IntegrationTestBuilder) AssertDestinationExists

func (s *IntegrationTestBuilder) AssertDestinationExists(filename string, b bool)

func (*IntegrationTestBuilder) AssertFileContent

func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...string)

func (*IntegrationTestBuilder) AssertFileContentExact

func (s *IntegrationTestBuilder) AssertFileContentExact(filename string, matches ...string)

func (*IntegrationTestBuilder) AssertFileCount

func (s *IntegrationTestBuilder) AssertFileCount(dirname string, expected int)

func (*IntegrationTestBuilder) AssertIsFileError

func (s *IntegrationTestBuilder) AssertIsFileError(err error) herrors.FileError

func (*IntegrationTestBuilder) AssertLogContains

func (s *IntegrationTestBuilder) AssertLogContains(text string)

func (*IntegrationTestBuilder) AssertLogMatches

func (s *IntegrationTestBuilder) AssertLogMatches(expression string)

func (*IntegrationTestBuilder) AssertRenderCountContent

func (s *IntegrationTestBuilder) AssertRenderCountContent(count int)

func (*IntegrationTestBuilder) AssertRenderCountPage

func (s *IntegrationTestBuilder) AssertRenderCountPage(count int)

func (*IntegrationTestBuilder) Build

func (*IntegrationTestBuilder) BuildE

func (*IntegrationTestBuilder) EditFileReplace

func (s *IntegrationTestBuilder) EditFileReplace(filename string, replacementFunc func(s string) string) *IntegrationTestBuilder

func (*IntegrationTestBuilder) EditFiles

func (s *IntegrationTestBuilder) EditFiles(filenameContent ...string) *IntegrationTestBuilder

func (*IntegrationTestBuilder) FileContent

func (s *IntegrationTestBuilder) FileContent(filename string) string

func (*IntegrationTestBuilder) Init

func (*IntegrationTestBuilder) LogString

func (s *IntegrationTestBuilder) LogString() string

func (*IntegrationTestBuilder) RemoveFiles

func (s *IntegrationTestBuilder) RemoveFiles(filenames ...string) *IntegrationTestBuilder

func (*IntegrationTestBuilder) RenameFile

func (s *IntegrationTestBuilder) RenameFile(old, new string) *IntegrationTestBuilder

type IntegrationTestConfig

type IntegrationTestConfig struct {
	T testing.TB

	// The files to use on txtar format, see
	// https://pkg.go.dev/golang.org/x/exp/cmd/txtar
	TxtarString string

	// COnfig to use as the base. We will also read the config from the txtar.
	BaseCfg config.Provider

	// Environment variables passed to the config loader.
	Environ []string

	// Whether to simulate server mode.
	Running bool

	// Will print the log buffer after the build
	Verbose bool

	LogLevel logg.Level

	// Whether it needs the real file system (e.g. for js.Build tests).
	NeedsOsFS bool

	// Whether to run GC after each build.
	RunGC bool

	// Do not remove the temp dir after the test.
	PrintAndKeepTempDir bool

	// Whether to run npm install before Build.
	NeedsNpmInstall bool

	WorkingDir string

	BuildCfg BuildCfg
}

type IntegrationTestDebugConfig

type IntegrationTestDebugConfig struct {
	Out io.Writer

	PrintDestinationFs bool
	PrintPagemap       bool

	PrefixDestinationFs string
	PrefixPagemap       string
}

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

AllRegularPages 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        any
	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 any) any

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

func (*ShortcodeWithPage) InnerDeindent

func (scp *ShortcodeWithPage) InnerDeindent() template.HTML

InnerDeindent returns the (potentially de-indented) inner content of the shortcode.

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]any) (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]any) (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 {
	*deps.Deps

	// Page navigation.
	*PageCollections
	// contains filtered or unexported fields
}

func (*Site) Author

func (s *Site) Author() map[string]any

func (*Site) Authors

func (s *Site) Authors() page.AuthorList

func (*Site) BaseURL

func (s *Site) BaseURL() string

Returns the BaseURL for this Site.

func (*Site) BuildDrafts

func (s *Site) BuildDrafts() bool

func (*Site) Config

func (s *Site) Config() page.SiteConfig

func (*Site) Copyright

func (s *Site) Copyright() string

func (*Site) Current

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

Returns Site currently rendering.

func (*Site) Data

func (s *Site) Data() map[string]any

Returns a map of all the data inside /data.

func (*Site) Debug

func (s *Site) Debug()

func (*Site) DisqusShortname deprecated

func (s *Site) DisqusShortname() string

Deprecated: Use .Site.Config.Services.Disqus.Shortname instead

func (*Site) GetIdentity

func (s *Site) GetIdentity() identity.Identity

Returns the identity of this site. This is for internal use only.

func (*Site) GetPage

func (s *Site) 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 (*Site) GetPageWithTemplateInfo

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

func (*Site) GetRelatedDocsHandler

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

func (*Site) GoogleAnalytics deprecated

func (s *Site) GoogleAnalytics() string

Deprecated: Use .Site.Config.Services.GoogleAnalytics.ID instead

func (*Site) Home

func (s *Site) Home() page.Page

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

func (*Site) HomeAbsURL

func (s *Site) HomeAbsURL() string

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

func (*Site) Hugo

func (s *Site) Hugo() hugo.HugoInfo

Returns a struct with some information about the build.

func (*Site) IsMultiLingual

func (s *Site) IsMultiLingual() bool

func (*Site) IsServer

func (s *Site) IsServer() bool

Returns true if we're running in a server. Deprecated: use hugo.IsServer instead

func (*Site) Language

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

func (*Site) LanguageCode

func (s *Site) LanguageCode() string

func (*Site) LanguagePrefix

func (s *Site) LanguagePrefix() string

func (*Site) Languages

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

func (*Site) LastChange

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

Returns the last modification date of the content.

func (*Site) MainSections

func (s *Site) MainSections() []string

MainSections returns the list of main sections.

func (*Site) Menus

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

func (*Site) Param

func (s *Site) Param(key any) (any, error)

func (*Site) Params

func (s *Site) Params() maps.Params

Returns the Params configured for this site.

func (s *Site) RSSLink() template.URL

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

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

Sections returns the top level sections.

func (*Site) ServerPort

func (s *Site) ServerPort() int

Returns the server port.

func (*Site) Site

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

func (*Site) SitemapAbsURL

func (s *Site) SitemapAbsURL() string

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

func (*Site) Sites

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

Returns all Sites for all languages.

func (*Site) Social

func (s *Site) Social() map[string]string

func (*Site) Taxonomies

func (s *Site) Taxonomies() page.TaxonomyList

func (*Site) Title

func (s *Site) Title() string

Returns the configured title for this Site.

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