all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
// Copyright 2024 The Hugo Authors. All rights reserved.
2023-01-04 12:24:36 -05:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package allconfig contains the full configuration for Hugo.
2023-05-18 16:51:11 -04:00
// <docsmeta>{ "name": "Configuration", "description": "This section holds all configuration options in Hugo." }</docsmeta>
2023-01-04 12:24:36 -05:00
package allconfig
import (
"errors"
"fmt"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
2023-05-17 12:45:23 -04:00
"sync"
2023-01-04 12:24:36 -05:00
"time"
"github.com/gohugoio/hugo/cache/filecache"
2024-05-17 11:06:47 -04:00
"github.com/gohugoio/hugo/cache/httpcache"
2023-10-26 03:38:13 -04:00
"github.com/gohugoio/hugo/common/hugo"
2023-05-21 08:25:16 -04:00
"github.com/gohugoio/hugo/common/loggers"
2023-01-04 12:24:36 -05:00
"github.com/gohugoio/hugo/common/maps"
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
"github.com/gohugoio/hugo/common/paths"
2024-01-30 05:43:20 -05:00
"github.com/gohugoio/hugo/common/types"
2023-01-04 12:24:36 -05:00
"github.com/gohugoio/hugo/common/urls"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/privacy"
"github.com/gohugoio/hugo/config/security"
"github.com/gohugoio/hugo/config/services"
2024-02-07 12:24:02 -05:00
"github.com/gohugoio/hugo/deploy/deployconfig"
2023-01-04 12:24:36 -05:00
"github.com/gohugoio/hugo/helpers"
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
2024-03-04 04:16:56 -05:00
"github.com/gohugoio/hugo/hugolib/segments"
2023-01-04 12:24:36 -05:00
"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"
"github.com/gohugoio/hugo/resources/images"
2023-07-28 04:53:47 -04:00
"github.com/gohugoio/hugo/resources/kinds"
2023-01-04 12:24:36 -05:00
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/pagemeta"
"github.com/spf13/afero"
xmaps "golang.org/x/exp/maps"
)
// InternalConfig is the internal configuration for Hugo, not read from any user provided config file.
type InternalConfig struct {
// Server mode?
Running bool
2023-07-19 03:23:48 -04:00
Quiet bool
Verbose bool
Clock string
Watch bool
2024-02-02 05:20:08 -05:00
FastRenderMode bool
2023-07-19 03:23:48 -04:00
LiveReloadPort int
2023-01-04 12:24:36 -05:00
}
2023-05-17 10:29:06 -04:00
// All non-params config keys for language.
var configLanguageKeys map [ string ] bool
func init ( ) {
skip := map [ string ] bool {
"internal" : true ,
"c" : true ,
"rootconfig" : true ,
}
configLanguageKeys = make ( map [ string ] bool )
addKeys := func ( v reflect . Value ) {
for i := 0 ; i < v . NumField ( ) ; i ++ {
name := strings . ToLower ( v . Type ( ) . Field ( i ) . Name )
if skip [ name ] {
continue
}
configLanguageKeys [ name ] = true
}
}
addKeys ( reflect . ValueOf ( Config { } ) )
addKeys ( reflect . ValueOf ( RootConfig { } ) )
addKeys ( reflect . ValueOf ( config . CommonDirs { } ) )
addKeys ( reflect . ValueOf ( langs . LanguageConfig { } ) )
}
2023-01-04 12:24:36 -05:00
type Config struct {
// For internal use only.
Internal InternalConfig ` mapstructure:"-" json:"-" `
// For internal use only.
2023-05-17 12:45:23 -04:00
C * ConfigCompiled ` mapstructure:"-" json:"-" `
2023-01-04 12:24:36 -05:00
RootConfig
// Author information.
2024-03-12 14:16:05 -04:00
// Deprecated: Use taxonomies instead.
2023-01-04 12:24:36 -05:00
Author map [ string ] any
// Social links.
2024-03-12 14:16:05 -04:00
// Deprecated: Use .Site.Params instead.
2023-01-04 12:24:36 -05:00
Social map [ string ] string
// The build configuration section contains build-related configuration options.
// <docsmeta>{"identifiers": ["build"] }</docsmeta>
Build config . BuildConfig ` mapstructure:"-" `
// The caches configuration section contains cache-related configuration options.
// <docsmeta>{"identifiers": ["caches"] }</docsmeta>
Caches filecache . Configs ` mapstructure:"-" `
2024-05-17 11:06:47 -04:00
// The httpcache configuration section contains HTTP-cache-related configuration options.
// <docsmeta>{"identifiers": ["httpcache"] }</docsmeta>
HTTPCache httpcache . Config ` mapstructure:"-" `
2023-01-04 12:24:36 -05:00
// The markup configuration section contains markup-related configuration options.
// <docsmeta>{"identifiers": ["markup"] }</docsmeta>
Markup markup_config . Config ` mapstructure:"-" `
// The mediatypes configuration section maps the MIME type (a string) to a configuration object for that type.
// <docsmeta>{"identifiers": ["mediatypes"], "refs": ["types:media:type"] }</docsmeta>
MediaTypes * config . ConfigNamespace [ map [ string ] media . MediaTypeConfig , media . Types ] ` mapstructure:"-" `
Imaging * config . ConfigNamespace [ images . ImagingConfig , images . ImagingConfigInternal ] ` mapstructure:"-" `
// The outputformats configuration sections maps a format name (a string) to a configuration object for that format.
OutputFormats * config . ConfigNamespace [ map [ string ] output . OutputFormatConfig , output . Formats ] ` mapstructure:"-" `
// The outputs configuration section maps a Page Kind (a string) to a slice of output formats.
// This can be overridden in the front matter.
Outputs map [ string ] [ ] string ` mapstructure:"-" `
// The cascade configuration section contains the top level front matter cascade configuration options,
// a slice of page matcher and params to apply to those pages.
Cascade * config . ConfigNamespace [ [ ] page . PageMatcherParamsConfig , map [ page . PageMatcher ] maps . Params ] ` mapstructure:"-" `
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
2024-03-04 04:16:56 -05:00
// The segments defines segments for the site. Used for partial/segmented builds.
Segments * config . ConfigNamespace [ map [ string ] segments . SegmentConfig , segments . Segments ] ` mapstructure:"-" `
2023-01-04 12:24:36 -05:00
// Menu configuration.
// <docsmeta>{"refs": ["config:languages:menus"] }</docsmeta>
Menus * config . ConfigNamespace [ map [ string ] navigation . MenuConfig , navigation . Menus ] ` mapstructure:"-" `
2024-02-07 12:24:02 -05:00
// The deployment configuration section contains for hugo deployconfig.
Deployment deployconfig . DeployConfig ` mapstructure:"-" `
2023-01-04 12:24:36 -05:00
// Module configuration.
Module modules . Config ` mapstructure:"-" `
// Front matter configuration.
Frontmatter pagemeta . FrontmatterConfig ` mapstructure:"-" `
// Minification configuration.
Minify minifiers . MinifyConfig ` mapstructure:"-" `
// Permalink configuration.
2023-06-26 09:31:01 -04:00
Permalinks map [ string ] map [ string ] string ` mapstructure:"-" `
2023-01-04 12:24:36 -05:00
// Taxonomy configuration.
Taxonomies map [ string ] string ` mapstructure:"-" `
// Sitemap configuration.
Sitemap config . SitemapConfig ` mapstructure:"-" `
// Related content configuration.
Related related . Config ` mapstructure:"-" `
// Server configuration.
Server config . Server ` mapstructure:"-" `
2024-06-07 11:38:33 -04:00
// Pagination configuration.
Pagination config . Pagination ` mapstructure:"-" `
2023-01-04 12:24:36 -05:00
// Privacy configuration.
Privacy privacy . Config ` mapstructure:"-" `
// Security configuration.
Security security . Config ` mapstructure:"-" `
// Services configuration.
Services services . Config ` mapstructure:"-" `
// User provided parameters.
// <docsmeta>{"refs": ["config:languages:params"] }</docsmeta>
Params maps . Params ` mapstructure:"-" `
// The languages configuration sections maps a language code (a string) to a configuration object for that language.
Languages map [ string ] langs . LanguageConfig ` mapstructure:"-" `
// UglyURLs configuration. Either a boolean or a sections map.
UglyURLs any ` mapstructure:"-" `
}
type configCompiler interface {
2023-05-21 08:25:16 -04:00
CompileConfig ( logger loggers . Logger ) error
2023-01-04 12:24:36 -05:00
}
func ( c Config ) cloneForLang ( ) * Config {
x := c
2023-05-17 12:45:23 -04:00
x . C = nil
2023-06-13 12:01:23 -04:00
copyStringSlice := func ( in [ ] string ) [ ] string {
if in == nil {
return nil
}
out := make ( [ ] string , len ( in ) )
copy ( out , in )
return out
}
// Copy all the slices to avoid sharing.
x . DisableKinds = copyStringSlice ( x . DisableKinds )
x . DisableLanguages = copyStringSlice ( x . DisableLanguages )
x . MainSections = copyStringSlice ( x . MainSections )
2024-01-30 03:23:21 -05:00
x . IgnoreLogs = copyStringSlice ( x . IgnoreLogs )
2023-06-13 12:01:23 -04:00
x . IgnoreFiles = copyStringSlice ( x . IgnoreFiles )
x . Theme = copyStringSlice ( x . Theme )
2023-05-17 12:45:23 -04:00
2023-01-04 12:24:36 -05:00
// Collapse all static dirs to one.
x . StaticDir = x . staticDirs ( )
// These will go away soon ...
x . StaticDir0 = nil
x . StaticDir1 = nil
x . StaticDir2 = nil
x . StaticDir3 = nil
x . StaticDir4 = nil
x . StaticDir5 = nil
x . StaticDir6 = nil
x . StaticDir7 = nil
x . StaticDir8 = nil
x . StaticDir9 = nil
x . StaticDir10 = nil
return & x
}
2023-05-21 08:25:16 -04:00
func ( c * Config ) CompileConfig ( logger loggers . Logger ) error {
2023-05-17 07:12:49 -04:00
var transientErr error
2023-01-04 12:24:36 -05:00
s := c . Timeout
if _ , err := strconv . Atoi ( s ) ; err == nil {
// A number, assume seconds.
s = s + "s"
}
timeout , err := time . ParseDuration ( s )
if err != nil {
return fmt . Errorf ( "failed to parse timeout: %s" , err )
}
disabledKinds := make ( map [ string ] bool )
for _ , kind := range c . DisableKinds {
2023-05-19 03:17:55 -04:00
kind = strings . ToLower ( kind )
2023-07-28 06:18:59 -04:00
if newKind := kinds . IsDeprecatedAndReplacedWith ( kind ) ; newKind != "" {
logger . Deprecatef ( false , "Kind %q used in disableKinds is deprecated, use %q instead." , kind , newKind )
2023-05-19 03:17:55 -04:00
// Legacy config.
2023-07-28 06:18:59 -04:00
kind = newKind
2023-05-19 03:17:55 -04:00
}
2023-07-28 06:04:03 -04:00
if kinds . GetKindAny ( kind ) == "" {
2023-07-28 06:18:59 -04:00
logger . Warnf ( "Unknown kind %q in disableKinds configuration." , kind )
2023-07-28 06:04:03 -04:00
continue
}
2023-05-19 03:17:55 -04:00
disabledKinds [ kind ] = true
2023-01-04 12:24:36 -05:00
}
kindOutputFormats := make ( map [ string ] output . Formats )
isRssDisabled := disabledKinds [ "rss" ]
outputFormats := c . OutputFormats . Config
for kind , formats := range c . Outputs {
2023-07-28 06:18:59 -04:00
if newKind := kinds . IsDeprecatedAndReplacedWith ( kind ) ; newKind != "" {
logger . Deprecatef ( false , "Kind %q used in outputs configuration is deprecated, use %q instead." , kind , newKind )
kind = newKind
}
2023-01-04 12:24:36 -05:00
if disabledKinds [ kind ] {
continue
}
2023-07-28 06:18:59 -04:00
if kinds . GetKindAny ( kind ) == "" {
logger . Warnf ( "Unknown kind %q in outputs configuration." , kind )
continue
}
2023-01-04 12:24:36 -05:00
for _ , format := range formats {
if isRssDisabled && format == "rss" {
// Legacy config.
continue
}
f , found := outputFormats . GetByName ( format )
if ! found {
2023-05-17 07:12:49 -04:00
transientErr = fmt . Errorf ( "unknown output format %q for kind %q" , format , kind )
continue
2023-01-04 12:24:36 -05:00
}
kindOutputFormats [ kind ] = append ( kindOutputFormats [ kind ] , f )
}
}
disabledLangs := make ( map [ string ] bool )
for _ , lang := range c . DisableLanguages {
disabledLangs [ lang ] = true
}
2023-07-08 10:16:06 -04:00
for lang , language := range c . Languages {
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
if ! language . Disabled && disabledLangs [ lang ] {
language . Disabled = true
c . Languages [ lang ] = language
}
2023-07-08 10:16:06 -04:00
if language . Disabled {
disabledLangs [ lang ] = true
if lang == c . DefaultContentLanguage {
return fmt . Errorf ( "cannot disable default content language %q" , lang )
}
}
}
2023-01-04 12:24:36 -05:00
2024-06-22 12:41:18 -04:00
for i , s := range c . IgnoreLogs {
c . IgnoreLogs [ i ] = strings . ToLower ( s )
}
2024-01-30 03:23:21 -05:00
ignoredLogIDs := make ( map [ string ] bool )
for _ , err := range c . IgnoreLogs {
2024-06-22 12:41:18 -04:00
ignoredLogIDs [ err ] = true
2023-01-04 12:24:36 -05:00
}
baseURL , err := urls . NewBaseURLFromString ( c . BaseURL )
if err != nil {
return err
}
isUglyURL := func ( section string ) bool {
switch v := c . UglyURLs . ( type ) {
case bool :
return v
case map [ string ] bool :
return v [ section ]
default :
return false
}
}
ignoreFile := func ( s string ) bool {
return false
}
if len ( c . IgnoreFiles ) > 0 {
regexps := make ( [ ] * regexp . Regexp , len ( c . IgnoreFiles ) )
for i , pattern := range c . IgnoreFiles {
var err error
regexps [ i ] , err = regexp . Compile ( pattern )
if err != nil {
return fmt . Errorf ( "failed to compile ignoreFiles pattern %q: %s" , pattern , err )
}
}
ignoreFile = func ( s string ) bool {
for _ , r := range regexps {
if r . MatchString ( s ) {
return true
}
}
return false
}
}
var clock time . Time
if c . Internal . Clock != "" {
var err error
clock , err = time . Parse ( time . RFC3339 , c . Internal . Clock )
if err != nil {
return fmt . Errorf ( "failed to parse clock: %s" , err )
}
}
2024-05-17 11:06:47 -04:00
httpCache , err := c . HTTPCache . Compile ( )
if err != nil {
return err
}
2024-06-07 11:38:33 -04:00
// Legacy paginate values.
if c . Paginate != 0 {
2024-06-08 16:28:02 -04:00
hugo . Deprecate ( "site config key paginate" , "Use paginator.pagerSize instead." , "v0.128.0" )
c . Pagination . PagerSize = c . Paginate
2024-06-07 11:38:33 -04:00
}
if c . PaginatePath != "" {
hugo . Deprecate ( "site config key paginatePath" , "Use paginator.path instead." , "v0.128.0" )
c . Pagination . Path = c . PaginatePath
}
2023-05-17 12:45:23 -04:00
c . C = & ConfigCompiled {
2023-01-04 12:24:36 -05:00
Timeout : timeout ,
BaseURL : baseURL ,
BaseURLLiveReload : baseURL ,
DisabledKinds : disabledKinds ,
DisabledLanguages : disabledLangs ,
2024-01-30 03:23:21 -05:00
IgnoredLogs : ignoredLogIDs ,
2023-01-04 12:24:36 -05:00
KindOutputFormats : kindOutputFormats ,
2024-03-17 06:12:33 -04:00
ContentTypes : media . DefaultContentTypes . FromTypes ( c . MediaTypes . Config ) ,
2023-01-04 12:24:36 -05:00
CreateTitle : helpers . GetTitleFunc ( c . TitleCaseStyle ) ,
IsUglyURLSection : isUglyURL ,
IgnoreFile : ignoreFile ,
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
2024-03-04 04:16:56 -05:00
SegmentFilter : c . Segments . Config . Get ( func ( s string ) { logger . Warnf ( "Render segment %q not found in configuration" , s ) } , c . RootConfig . RenderSegments ... ) ,
2023-01-04 12:24:36 -05:00
MainSections : c . MainSections ,
Clock : clock ,
2024-05-17 11:06:47 -04:00
HTTPCache : httpCache ,
2023-05-17 07:12:49 -04:00
transientErr : transientErr ,
2023-01-04 12:24:36 -05:00
}
for _ , s := range allDecoderSetups {
if getCompiler := s . getCompiler ; getCompiler != nil {
2023-05-21 08:25:16 -04:00
if err := getCompiler ( c ) . CompileConfig ( logger ) ; err != nil {
2023-01-04 12:24:36 -05:00
return err
}
}
}
return nil
}
2023-05-17 12:45:23 -04:00
func ( c * Config ) IsKindEnabled ( kind string ) bool {
2023-01-04 12:24:36 -05:00
return ! c . C . DisabledKinds [ kind ]
}
2023-05-17 12:45:23 -04:00
func ( c * Config ) IsLangDisabled ( lang string ) bool {
2023-01-04 12:24:36 -05:00
return c . C . DisabledLanguages [ lang ]
}
// ConfigCompiled holds values and functions that are derived from the config.
type ConfigCompiled struct {
Timeout time . Duration
BaseURL urls . BaseURL
BaseURLLiveReload urls . BaseURL
2024-04-13 12:22:19 -04:00
ServerInterface string
2023-01-04 12:24:36 -05:00
KindOutputFormats map [ string ] output . Formats
2024-03-17 06:12:33 -04:00
ContentTypes media . ContentTypes
2023-01-04 12:24:36 -05:00
DisabledKinds map [ string ] bool
DisabledLanguages map [ string ] bool
2024-01-30 03:23:21 -05:00
IgnoredLogs map [ string ] bool
2023-01-04 12:24:36 -05:00
CreateTitle func ( s string ) string
IsUglyURLSection func ( section string ) bool
IgnoreFile func ( filename string ) bool
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
2024-03-04 04:16:56 -05:00
SegmentFilter segments . SegmentFilter
2023-01-04 12:24:36 -05:00
MainSections [ ] string
Clock time . Time
2024-05-17 11:06:47 -04:00
HTTPCache httpcache . ConfigCompiled
2023-05-17 07:12:49 -04:00
// This is set to the last transient error found during config compilation.
2023-05-17 10:29:06 -04:00
// With themes/modules we compute the configuration in multiple passes, and
2023-05-17 07:12:49 -04:00
// errors with missing output format definitions may resolve itself.
transientErr error
2023-05-17 12:45:23 -04:00
mu sync . Mutex
2023-01-04 12:24:36 -05:00
}
// This may be set after the config is compiled.
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
func ( c * ConfigCompiled ) SetMainSections ( sections [ ] string ) {
2023-05-17 12:45:23 -04:00
c . mu . Lock ( )
defer c . mu . Unlock ( )
2023-01-04 12:24:36 -05:00
c . MainSections = sections
}
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
// IsMainSectionsSet returns whether the main sections have been set.
func ( c * ConfigCompiled ) IsMainSectionsSet ( ) bool {
c . mu . Lock ( )
defer c . mu . Unlock ( )
return c . MainSections != nil
}
2023-01-04 12:24:36 -05:00
// This is set after the config is compiled by the server command.
2024-04-13 12:22:19 -04:00
func ( c * ConfigCompiled ) SetServerInfo ( baseURL , baseURLLiveReload urls . BaseURL , serverInterface string ) {
2023-01-04 12:24:36 -05:00
c . BaseURL = baseURL
c . BaseURLLiveReload = baseURLLiveReload
2024-04-13 12:22:19 -04:00
c . ServerInterface = serverInterface
2023-01-04 12:24:36 -05:00
}
// RootConfig holds all the top-level configuration options in Hugo
type RootConfig struct {
// The base URL of the site.
// Note that the default value is empty, but Hugo requires a valid URL (e.g. "https://example.com/") to work properly.
// <docsmeta>{"identifiers": ["URL"] }</docsmeta>
BaseURL string
// Whether to build content marked as draft.X
// <docsmeta>{"identifiers": ["draft"] }</docsmeta>
BuildDrafts bool
// Whether to build content with expiryDate in the past.
// <docsmeta>{"identifiers": ["expiryDate"] }</docsmeta>
BuildExpired bool
// Whether to build content with publishDate in the future.
// <docsmeta>{"identifiers": ["publishDate"] }</docsmeta>
BuildFuture bool
// Copyright information.
Copyright string
2023-05-22 13:11:12 -04:00
// The language to apply to content without any language indicator.
2023-01-04 12:24:36 -05:00
DefaultContentLanguage string
2023-05-22 13:11:12 -04:00
// By default, we put the default content language in the root and the others below their language ID, e.g. /no/.
2023-01-04 12:24:36 -05:00
// Set this to true to put all languages below their language ID.
DefaultContentLanguageInSubdir bool
// Disable creation of alias redirect pages.
DisableAliases bool
// Disable lower casing of path segments.
DisablePathToLower bool
// Disable page kinds from build.
DisableKinds [ ] string
// A list of languages to disable.
DisableLanguages [ ] string
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
2024-03-04 04:16:56 -05:00
// The named segments to render.
// This needs to match the name of the segment in the segments configuration.
RenderSegments [ ] string
2023-01-04 12:24:36 -05:00
// Disable the injection of the Hugo generator tag on the home page.
DisableHugoGeneratorInject bool
2023-07-19 03:23:48 -04:00
// Disable live reloading in server mode.
DisableLiveReload bool
2023-01-04 12:24:36 -05:00
// Enable replacement in Pages' Content of Emoji shortcodes with their equivalent Unicode characters.
// <docsmeta>{"identifiers": ["Content", "Unicode"] }</docsmeta>
EnableEmoji bool
// THe main section(s) of the site.
// If not set, Hugo will try to guess this from the content.
MainSections [ ] string
// Enable robots.txt generation.
EnableRobotsTXT bool
// When enabled, Hugo will apply Git version information to each Page if possible, which
// can be used to keep lastUpdated in synch and to print version information.
// <docsmeta>{"identifiers": ["Page"] }</docsmeta>
EnableGitInfo bool
// Enable to track, calculate and print metrics.
TemplateMetrics bool
// Enable to track, print and calculate metric hints.
TemplateMetricsHints bool
// Enable to disable the build lock file.
NoBuildLock bool
2024-01-30 03:23:21 -05:00
// A list of log IDs to ignore.
IgnoreLogs [ ] string
2023-01-04 12:24:36 -05:00
// A list of regexps that match paths to ignore.
// Deprecated: Use the settings on module imports.
IgnoreFiles [ ] string
// Ignore cache.
IgnoreCache bool
// Enable to print greppable placeholders (on the form "[i18n] TRANSLATIONID") for missing translation strings.
EnableMissingTranslationPlaceholders bool
2023-06-16 02:17:42 -04:00
// Enable to panic on warning log entries. This may make it easier to detect the source.
PanicOnWarning bool
2023-01-04 12:24:36 -05:00
// The configured environment. Default is "development" for server and "production" for build.
Environment string
// The default language code.
LanguageCode string
// Enable if the site content has CJK language (Chinese, Japanese, or Korean). This affects how Hugo counts words.
HasCJKLanguage bool
// The default number of pages per page when paginating.
2024-06-07 11:38:33 -04:00
// Deprecated: Use the Pagination struct.
2023-01-04 12:24:36 -05:00
Paginate int
// The path to use when creating pagination URLs, e.g. "page" in /page/2/.
2024-06-07 11:38:33 -04:00
// Deprecated: Use the Pagination struct.
2023-01-04 12:24:36 -05:00
PaginatePath string
// Whether to pluralize default list titles.
// Note that this currently only works for English, but you can provide your own title in the content file's front matter.
PluralizeListTitles bool
2024-02-22 14:51:22 -05:00
// Whether to capitalize automatic page titles, applicable to section, taxonomy, and term pages.
CapitalizeListTitles bool
2023-01-04 12:24:36 -05:00
// Make all relative URLs absolute using the baseURL.
// <docsmeta>{"identifiers": ["baseURL"] }</docsmeta>
CanonifyURLs bool
// Enable this to make all relative URLs relative to content root. Note that this does not affect absolute URLs.
RelativeURLs bool
// Removes non-spacing marks from composite characters in content paths.
RemovePathAccents bool
// Whether to track and print unused templates during the build.
PrintUnusedTemplates bool
2023-06-30 02:47:11 -04:00
// Enable to print warnings for missing translation strings.
PrintI18nWarnings bool
// ENable to print warnings for multiple files published to the same destination.
PrintPathWarnings bool
2023-01-04 12:24:36 -05:00
// URL to be used as a placeholder when a page reference cannot be found in ref or relref. Is used as-is.
RefLinksNotFoundURL string
// When using ref or relref to resolve page links and a link cannot be resolved, it will be logged with this log level.
// Valid values are ERROR (default) or WARNING. Any ERROR will fail the build (exit -1).
RefLinksErrorLevel string
// This will create a menu with all the sections as menu items and all the sections’ pages as “shadow-members”.
SectionPagesMenu string
// The length of text in words to show in a .Summary.
SummaryLength int
// The site title.
Title string
// The theme(s) to use.
// See Modules for more a more flexible way to load themes.
Theme [ ] string
2023-07-08 16:58:11 -04:00
// Timeout for generating page contents, specified as a duration or in seconds.
2023-01-04 12:24:36 -05:00
Timeout string
// The time zone (or location), e.g. Europe/Oslo, used to parse front matter dates without such information and in the time function.
TimeZone string
// Set titleCaseStyle to specify the title style used by the title template function and the automatic section titles in Hugo.
// It defaults to AP Stylebook for title casing, but you can also set it to Chicago or Go (every word starts with a capital letter).
TitleCaseStyle string
// The editor used for opening up new content.
NewContentEditor string
// Don't sync modification time of files for the static mounts.
NoTimes bool
// Don't sync modification time of files for the static mounts.
NoChmod bool
// Clean the destination folder before a new build.
// This currently only handles static files.
CleanDestinationDir bool
// A Glob pattern of module paths to ignore in the _vendor folder.
IgnoreVendorPaths string
config . CommonDirs ` mapstructure:",squash" `
// The odd constructs below are kept for backwards compatibility.
// Deprecated: Use module mount config instead.
StaticDir [ ] string
// Deprecated: Use module mount config instead.
StaticDir0 [ ] string
// Deprecated: Use module mount config instead.
StaticDir1 [ ] string
// Deprecated: Use module mount config instead.
StaticDir2 [ ] string
// Deprecated: Use module mount config instead.
StaticDir3 [ ] string
// Deprecated: Use module mount config instead.
StaticDir4 [ ] string
// Deprecated: Use module mount config instead.
StaticDir5 [ ] string
// Deprecated: Use module mount config instead.
StaticDir6 [ ] string
// Deprecated: Use module mount config instead.
StaticDir7 [ ] string
// Deprecated: Use module mount config instead.
StaticDir8 [ ] string
// Deprecated: Use module mount config instead.
StaticDir9 [ ] string
// Deprecated: Use module mount config instead.
StaticDir10 [ ] string
}
func ( c RootConfig ) staticDirs ( ) [ ] string {
var dirs [ ] string
dirs = append ( dirs , c . StaticDir ... )
dirs = append ( dirs , c . StaticDir0 ... )
dirs = append ( dirs , c . StaticDir1 ... )
dirs = append ( dirs , c . StaticDir2 ... )
dirs = append ( dirs , c . StaticDir3 ... )
dirs = append ( dirs , c . StaticDir4 ... )
dirs = append ( dirs , c . StaticDir5 ... )
dirs = append ( dirs , c . StaticDir6 ... )
dirs = append ( dirs , c . StaticDir7 ... )
dirs = append ( dirs , c . StaticDir8 ... )
dirs = append ( dirs , c . StaticDir9 ... )
dirs = append ( dirs , c . StaticDir10 ... )
return helpers . UniqueStringsReuse ( dirs )
}
type Configs struct {
Base * Config
LoadingInfo config . LoadConfigResult
LanguageConfigMap map [ string ] * Config
LanguageConfigSlice [ ] * Config
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
IsMultihost bool
2023-01-04 12:24:36 -05:00
Modules modules . Modules
ModulesClient * modules . Client
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
// All below is set in Init.
Languages langs . Languages
LanguagesDefaultFirst langs . Languages
2024-02-09 06:52:36 -05:00
ContentPathParser * paths . PathParser
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
2023-01-04 12:24:36 -05:00
configLangs [ ] config . AllProvider
}
2024-02-26 10:13:05 -05:00
func ( c * Configs ) Validate ( logger loggers . Logger ) error {
for p := range c . Base . Cascade . Config {
page . CheckCascadePattern ( logger , p )
}
return nil
}
2023-05-17 07:12:49 -04:00
// transientErr returns the last transient error found during config compilation.
func ( c * Configs ) transientErr ( ) error {
for _ , l := range c . LanguageConfigSlice {
if l . C . transientErr != nil {
return l . C . transientErr
}
}
return nil
}
2023-01-04 12:24:36 -05:00
func ( c * Configs ) IsZero ( ) bool {
// A config always has at least one language.
return c == nil || len ( c . Languages ) == 0
}
func ( c * Configs ) Init ( ) error {
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
var languages langs . Languages
defaultContentLanguage := c . Base . DefaultContentLanguage
for k , v := range c . LanguageConfigMap {
c . LanguageConfigSlice = append ( c . LanguageConfigSlice , v )
languageConf := v . Languages [ k ]
language , err := langs . NewLanguage ( k , defaultContentLanguage , v . TimeZone , languageConf )
if err != nil {
return err
}
languages = append ( languages , language )
}
// Sort the sites by language weight (if set) or lang.
sort . Slice ( languages , func ( i , j int ) bool {
li := languages [ i ]
lj := languages [ j ]
if li . Weight != lj . Weight {
return li . Weight < lj . Weight
}
return li . Lang < lj . Lang
} )
for _ , l := range languages {
c . LanguageConfigSlice = append ( c . LanguageConfigSlice , c . LanguageConfigMap [ l . Lang ] )
}
// Filter out disabled languages.
var n int
for _ , l := range languages {
if ! l . Disabled {
languages [ n ] = l
n ++
}
}
languages = languages [ : n ]
var languagesDefaultFirst langs . Languages
for _ , l := range languages {
if l . Lang == defaultContentLanguage {
languagesDefaultFirst = append ( languagesDefaultFirst , l )
}
}
for _ , l := range languages {
if l . Lang != defaultContentLanguage {
languagesDefaultFirst = append ( languagesDefaultFirst , l )
}
}
c . Languages = languages
c . LanguagesDefaultFirst = languagesDefaultFirst
2024-02-01 03:37:05 -05:00
2024-03-17 06:12:33 -04:00
c . ContentPathParser = & paths . PathParser { LanguageIndex : languagesDefaultFirst . AsIndexSet ( ) , IsLangDisabled : c . Base . IsLangDisabled , IsContentExt : c . Base . C . ContentTypes . IsContentSuffix }
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
2023-01-04 12:24:36 -05:00
c . configLangs = make ( [ ] config . AllProvider , len ( c . Languages ) )
for i , l := range c . LanguagesDefaultFirst {
c . configLangs [ i ] = ConfigLanguage {
m : c ,
config : c . LanguageConfigMap [ l . Lang ] ,
baseConfig : c . LoadingInfo . BaseConfig ,
language : l ,
}
}
if len ( c . Modules ) == 0 {
return errors . New ( "no modules loaded (ned at least the main module)" )
}
// Apply default project mounts.
if err := modules . ApplyProjectConfigDefaults ( c . Modules [ 0 ] , c . configLangs ... ) ; err != nil {
return err
}
2023-06-01 03:30:16 -04:00
// We should consolidate this, but to get a full view of the mounts in e.g. "hugo config" we need to
// transfer any default mounts added above to the config used to print the config.
for _ , m := range c . Modules [ 0 ] . Mounts ( ) {
var found bool
for _ , cm := range c . Base . Module . Mounts {
if cm . Source == m . Source && cm . Target == m . Target && cm . Lang == m . Lang {
found = true
break
}
}
if ! found {
c . Base . Module . Mounts = append ( c . Base . Module . Mounts , m )
}
}
2023-06-01 03:53:40 -04:00
// Transfer the changed mounts to the language versions (all share the same mount set, but can be displayed in different languages).
for _ , l := range c . LanguageConfigSlice {
l . Module . Mounts = c . Base . Module . Mounts
}
2023-01-04 12:24:36 -05:00
return nil
}
func ( c Configs ) ConfigLangs ( ) [ ] config . AllProvider {
return c . configLangs
}
func ( c Configs ) GetFirstLanguageConfig ( ) config . AllProvider {
return c . configLangs [ 0 ]
}
func ( c Configs ) GetByLang ( lang string ) config . AllProvider {
for _ , l := range c . configLangs {
if l . Language ( ) . Lang == lang {
return l
}
}
return nil
}
2023-05-21 08:25:16 -04:00
// fromLoadConfigResult creates a new Config from res.
func fromLoadConfigResult ( fs afero . Fs , logger loggers . Logger , res config . LoadConfigResult ) ( * Configs , error ) {
2023-01-04 12:24:36 -05:00
if ! res . Cfg . IsSet ( "languages" ) {
// We need at least one
lang := res . Cfg . GetString ( "defaultContentLanguage" )
res . Cfg . Set ( "languages" , maps . Params { lang : maps . Params { } } )
}
bcfg := res . BaseConfig
cfg := res . Cfg
all := & Config { }
Use os.UserCacheDir as first fallback if cacheDir is not set
We will now try
1. cacheDir (or, commonly set in environment as `HUGO_CACHEDIR`)
2. if on Netlify we use `/opt/build/cache/hugo_cache/`
3. os.UserCacheDir
4. A temp dir
Storing the cache, especially the module cache, in a temporary idea has had lots of hard to debug issues, especially on MacOS,
which this commit tries to fix.
This should also make it easier to locate the Hugo cache:
>UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own
application-specific subdirectory within this one and use that.
>
>On Unix systems, it returns $XDG_CACHE_HOME as specified by
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it
returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache.
>
>If the location cannot be determined (for example, $HOME is not defined), then it will return an error.
Fixes #11286
Fixes #11291
2023-07-27 14:59:47 -04:00
2023-07-31 05:20:37 -04:00
err := decodeConfigFromParams ( fs , logger , bcfg , cfg , all , nil )
2023-01-04 12:24:36 -05:00
if err != nil {
return nil , err
}
langConfigMap := make ( map [ string ] * Config )
languagesConfig := cfg . GetStringMap ( "languages" )
2024-03-12 11:18:23 -04:00
var isMultihost bool
2023-01-04 12:24:36 -05:00
2023-05-21 08:25:16 -04:00
if err := all . CompileConfig ( logger ) ; err != nil {
2023-01-04 12:24:36 -05:00
return nil , err
}
for k , v := range languagesConfig {
mergedConfig := config . New ( )
var differentRootKeys [ ] string
switch x := v . ( type ) {
case maps . Params :
2023-05-17 10:29:06 -04:00
var params maps . Params
pv , found := x [ "params" ]
if found {
params = pv . ( maps . Params )
} else {
params = maps . Params {
maps . MergeStrategyKey : maps . ParamsMergeStrategyDeep ,
}
x [ "params" ] = params
}
2023-01-04 12:24:36 -05:00
for kk , vv := range x {
2023-05-17 10:29:06 -04:00
if kk == "_merge" {
continue
}
if kk != maps . MergeStrategyKey && ! configLanguageKeys [ kk ] {
// This should have been placed below params.
2023-05-18 16:51:11 -04:00
// We accidentally allowed it in the past, so we need to support it a little longer,
2023-05-17 10:29:06 -04:00
// But log a warning.
if _ , found := params [ kk ] ; ! found {
2023-10-26 03:38:13 -04:00
hugo . Deprecate ( fmt . Sprintf ( "config: languages.%s.%s: custom params on the language top level" , k , kk ) , fmt . Sprintf ( "Put the value below [languages.%s.params]. See https://gohugo.io/content-management/multilingual/#changes-in-hugo-01120" , k ) , "v0.112.0" )
2023-05-17 10:29:06 -04:00
params [ kk ] = vv
}
}
2023-01-04 12:24:36 -05:00
if kk == "baseurl" {
// baseURL configure don the language level is a multihost setup.
2024-03-12 11:18:23 -04:00
isMultihost = true
2023-01-04 12:24:36 -05:00
}
mergedConfig . Set ( kk , vv )
2023-05-30 05:38:29 -04:00
rootv := cfg . Get ( kk )
if rootv != nil && cfg . IsSet ( kk ) {
2023-01-04 12:24:36 -05:00
// This overrides a root key and potentially needs a merge.
if ! reflect . DeepEqual ( rootv , vv ) {
switch vvv := vv . ( type ) {
case maps . Params :
differentRootKeys = append ( differentRootKeys , kk )
// Use the language value as base.
mergedConfigEntry := xmaps . Clone ( vvv )
// Merge in the root value.
maps . MergeParams ( mergedConfigEntry , rootv . ( maps . Params ) )
mergedConfig . Set ( kk , mergedConfigEntry )
default :
// Apply new values to the root.
differentRootKeys = append ( differentRootKeys , "" )
}
}
} else {
2023-05-20 05:17:43 -04:00
switch vv . ( type ) {
case maps . Params :
differentRootKeys = append ( differentRootKeys , kk )
default :
// Apply new values to the root.
differentRootKeys = append ( differentRootKeys , "" )
}
2023-01-04 12:24:36 -05:00
}
}
differentRootKeys = helpers . UniqueStringsSorted ( differentRootKeys )
if len ( differentRootKeys ) == 0 {
langConfigMap [ k ] = all
continue
}
// Create a copy of the complete config and replace the root keys with the language specific ones.
clone := all . cloneForLang ( )
2023-06-13 12:01:23 -04:00
2023-07-31 05:20:37 -04:00
if err := decodeConfigFromParams ( fs , logger , bcfg , mergedConfig , clone , differentRootKeys ) ; err != nil {
2023-01-04 12:24:36 -05:00
return nil , fmt . Errorf ( "failed to decode config for language %q: %w" , k , err )
}
2023-05-21 08:25:16 -04:00
if err := clone . CompileConfig ( logger ) ; err != nil {
2023-01-04 12:24:36 -05:00
return nil , err
}
2023-06-13 12:01:23 -04:00
2024-01-30 05:43:20 -05:00
// Adjust Goldmark config defaults for multilingual, single-host sites.
2024-03-12 11:18:23 -04:00
if len ( languagesConfig ) > 1 && ! isMultihost && ! clone . Markup . Goldmark . DuplicateResourceFiles {
2024-01-30 05:43:20 -05:00
if ! clone . Markup . Goldmark . DuplicateResourceFiles {
if clone . Markup . Goldmark . RenderHooks . Link . EnableDefault == nil {
clone . Markup . Goldmark . RenderHooks . Link . EnableDefault = types . NewBool ( true )
}
if clone . Markup . Goldmark . RenderHooks . Image . EnableDefault == nil {
clone . Markup . Goldmark . RenderHooks . Image . EnableDefault = types . NewBool ( true )
}
}
}
2023-01-04 12:24:36 -05:00
langConfigMap [ k ] = clone
case maps . ParamsMergeStrategy :
default :
panic ( fmt . Sprintf ( "unknown type in languages config: %T" , v ) )
}
}
bcfg . PublishDir = all . PublishDir
res . BaseConfig = bcfg
Use os.UserCacheDir as first fallback if cacheDir is not set
We will now try
1. cacheDir (or, commonly set in environment as `HUGO_CACHEDIR`)
2. if on Netlify we use `/opt/build/cache/hugo_cache/`
3. os.UserCacheDir
4. A temp dir
Storing the cache, especially the module cache, in a temporary idea has had lots of hard to debug issues, especially on MacOS,
which this commit tries to fix.
This should also make it easier to locate the Hugo cache:
>UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own
application-specific subdirectory within this one and use that.
>
>On Unix systems, it returns $XDG_CACHE_HOME as specified by
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it
returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache.
>
>If the location cannot be determined (for example, $HOME is not defined), then it will return an error.
Fixes #11286
Fixes #11291
2023-07-27 14:59:47 -04:00
all . CommonDirs . CacheDir = bcfg . CacheDir
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
for _ , l := range langConfigMap {
Use os.UserCacheDir as first fallback if cacheDir is not set
We will now try
1. cacheDir (or, commonly set in environment as `HUGO_CACHEDIR`)
2. if on Netlify we use `/opt/build/cache/hugo_cache/`
3. os.UserCacheDir
4. A temp dir
Storing the cache, especially the module cache, in a temporary idea has had lots of hard to debug issues, especially on MacOS,
which this commit tries to fix.
This should also make it easier to locate the Hugo cache:
>UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own
application-specific subdirectory within this one and use that.
>
>On Unix systems, it returns $XDG_CACHE_HOME as specified by
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it
returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache.
>
>If the location cannot be determined (for example, $HOME is not defined), then it will return an error.
Fixes #11286
Fixes #11291
2023-07-27 14:59:47 -04:00
l . CommonDirs . CacheDir = bcfg . CacheDir
}
2023-01-04 12:24:36 -05:00
cm := & Configs {
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.
Closes #11455
Closes #11549
This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.
The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.
A list of the notable new features:
* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.
New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.
This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):
Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.
Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).
Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2023-12-24 13:11:05 -05:00
Base : all ,
LanguageConfigMap : langConfigMap ,
LoadingInfo : res ,
2024-03-12 11:18:23 -04:00
IsMultihost : isMultihost ,
2023-01-04 12:24:36 -05:00
}
return cm , nil
}
2023-07-31 05:20:37 -04:00
func decodeConfigFromParams ( fs afero . Fs , logger loggers . Logger , bcfg config . BaseConfig , p config . Provider , target * Config , keys [ ] string ) error {
2023-01-04 12:24:36 -05:00
var decoderSetups [ ] decodeWeight
if len ( keys ) == 0 {
for _ , v := range allDecoderSetups {
decoderSetups = append ( decoderSetups , v )
}
} else {
for _ , key := range keys {
if v , found := allDecoderSetups [ key ] ; found {
decoderSetups = append ( decoderSetups , v )
} else {
2023-07-31 05:20:37 -04:00
logger . Warnf ( "Skip unknown config key %q" , key )
2023-01-04 12:24:36 -05:00
}
}
}
// Sort them to get the dependency order right.
sort . Slice ( decoderSetups , func ( i , j int ) bool {
ki , kj := decoderSetups [ i ] , decoderSetups [ j ]
if ki . weight == kj . weight {
return ki . key < kj . key
}
return ki . weight < kj . weight
} )
for _ , v := range decoderSetups {
2024-02-26 10:13:05 -05:00
p := decodeConfig { p : p , c : target , fs : fs , bcfg : bcfg }
2023-01-04 12:24:36 -05:00
if err := v . decode ( v , p ) ; err != nil {
return fmt . Errorf ( "failed to decode %q: %w" , v . key , err )
}
}
return nil
}
func createDefaultOutputFormats ( allFormats output . Formats ) map [ string ] [ ] string {
if len ( allFormats ) == 0 {
panic ( "no output formats" )
}
rssOut , rssFound := allFormats . GetByName ( output . RSSFormat . Name )
htmlOut , _ := allFormats . GetByName ( output . HTMLFormat . Name )
defaultListTypes := [ ] string { htmlOut . Name }
if rssFound {
defaultListTypes = append ( defaultListTypes , rssOut . Name )
}
m := map [ string ] [ ] string {
2023-07-28 04:53:47 -04:00
kinds . KindPage : { htmlOut . Name } ,
kinds . KindHome : defaultListTypes ,
kinds . KindSection : defaultListTypes ,
kinds . KindTerm : defaultListTypes ,
kinds . KindTaxonomy : defaultListTypes ,
2023-01-04 12:24:36 -05:00
}
// May be disabled
if rssFound {
m [ "rss" ] = [ ] string { rssOut . Name }
}
return m
}