diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-03-04 10:16:56 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-03-16 15:53:26 +0100 |
commit | 1f1c62e6c7fb5c420710fd15ac11995e6c546897 (patch) | |
tree | 4234ab21f7b4c9e73eccaa0276d52413b8cea2bf /config | |
parent | f1d755965fba9a8d99a4e423c6e231cf7411b4a2 (diff) | |
download | hugo-1f1c62e6c7fb5c420710fd15ac11995e6c546897.tar.gz hugo-1f1c62e6c7fb5c420710fd15ac11995e6c546897.zip |
Add segments config + --renderSegments flag
Named segments can be defined in `hugo.toml`.
* Eeach segment consists of zero or more `exclude` filters and zero or more `include` filters.
* Eeach filter consists of one or more field Glob matchers.
* Eeach filter in a section (`exclude` or `include`) is ORed together, each matcher in a filter is ANDed together.
The current list of fields that can be filtered are:
* path as defined in https://gohugo.io/methods/page/path/
* kind
* lang
* output (output format, e.g. html).
It is recommended to put coarse grained filters (e.g. for language and output format) in the excludes section, e.g.:
```toml
[segments.segment1]
[[segments.segment1.excludes]]
lang = "n*"
[[segments.segment1.excludes]]
no = "en"
output = "rss"
[[segments.segment1.includes]]
term = "{home,term,taxonomy}"
[[segments.segment1.includes]]
path = "{/docs,/docs/**}"
```
By default, Hugo will render all segments, but you can enable filters by setting the `renderSegments` option or `--renderSegments` flag, e.g:
```
hugo --renderSegments segment1,segment2
```
For segment `segment1` in the configuration above, this will:
* Skip rendering of all languages matching `n*`, e.g. `no`.
* Skip rendering of the output format `rss` for the `en` language.
* It will render all pages of kind `home`, `term` or `taxonomy`
* It will render the `/docs` section and all pages below.
Fixes #10106
Diffstat (limited to 'config')
-rw-r--r-- | config/allconfig/allconfig.go | 10 | ||||
-rw-r--r-- | config/allconfig/alldecoders.go | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go index 3a7908d55..f0e72dabc 100644 --- a/config/allconfig/allconfig.go +++ b/config/allconfig/allconfig.go @@ -39,6 +39,7 @@ import ( "github.com/gohugoio/hugo/config/services" "github.com/gohugoio/hugo/deploy/deployconfig" "github.com/gohugoio/hugo/helpers" + "github.com/gohugoio/hugo/hugolib/segments" "github.com/gohugoio/hugo/langs" "github.com/gohugoio/hugo/markup/markup_config" "github.com/gohugoio/hugo/media" @@ -139,6 +140,9 @@ type Config struct { // a slice of page matcher and params to apply to those pages. Cascade *config.ConfigNamespace[[]page.PageMatcherParamsConfig, map[page.PageMatcher]maps.Params] `mapstructure:"-"` + // The segments defines segments for the site. Used for partial/segmented builds. + Segments *config.ConfigNamespace[map[string]segments.SegmentConfig, segments.Segments] `mapstructure:"-"` + // Menu configuration. // <docsmeta>{"refs": ["config:languages:menus"] }</docsmeta> Menus *config.ConfigNamespace[map[string]navigation.MenuConfig, navigation.Menus] `mapstructure:"-"` @@ -366,6 +370,7 @@ func (c *Config) CompileConfig(logger loggers.Logger) error { CreateTitle: helpers.GetTitleFunc(c.TitleCaseStyle), IsUglyURLSection: isUglyURL, IgnoreFile: ignoreFile, + SegmentFilter: c.Segments.Config.Get(func(s string) { logger.Warnf("Render segment %q not found in configuration", s) }, c.RootConfig.RenderSegments...), MainSections: c.MainSections, Clock: clock, transientErr: transientErr, @@ -402,6 +407,7 @@ type ConfigCompiled struct { CreateTitle func(s string) string IsUglyURLSection func(section string) bool IgnoreFile func(filename string) bool + SegmentFilter segments.SegmentFilter MainSections []string Clock time.Time @@ -474,6 +480,10 @@ type RootConfig struct { // A list of languages to disable. DisableLanguages []string + // The named segments to render. + // This needs to match the name of the segment in the segments configuration. + RenderSegments []string + // Disable the injection of the Hugo generator tag on the home page. DisableHugoGeneratorInject bool diff --git a/config/allconfig/alldecoders.go b/config/allconfig/alldecoders.go index 5d31d5d35..7d968e4ad 100644 --- a/config/allconfig/alldecoders.go +++ b/config/allconfig/alldecoders.go @@ -25,11 +25,13 @@ import ( "github.com/gohugoio/hugo/config/security" "github.com/gohugoio/hugo/config/services" "github.com/gohugoio/hugo/deploy/deployconfig" + "github.com/gohugoio/hugo/hugolib/segments" "github.com/gohugoio/hugo/langs" "github.com/gohugoio/hugo/markup/markup_config" "github.com/gohugoio/hugo/media" "github.com/gohugoio/hugo/minifiers" "github.com/gohugoio/hugo/modules" + "github.com/gohugoio/hugo/navigation" "github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/related" @@ -120,6 +122,14 @@ var allDecoderSetups = map[string]decodeWeight{ return err }, }, + "segments": { + key: "segments", + decode: func(d decodeWeight, p decodeConfig) error { + var err error + p.c.Segments, err = segments.DecodeSegments(p.p.GetStringMap(d.key)) + return err + }, + }, "server": { key: "server", decode: func(d decodeWeight, p decodeConfig) error { |