2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2017-03-05 12:23:00 -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.
|
|
|
|
|
2022-12-30 03:20:58 -05:00
|
|
|
// Package output contains Output Format types and functions.
|
2017-03-05 12:23:00 -05:00
|
|
|
package output
|
|
|
|
|
|
|
|
import (
|
2017-04-05 10:18:53 -04:00
|
|
|
"encoding/json"
|
2017-03-08 07:45:33 -05:00
|
|
|
"fmt"
|
2017-04-03 11:00:23 -04:00
|
|
|
"sort"
|
2017-03-08 07:45:33 -05:00
|
|
|
"strings"
|
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/media"
|
2017-03-05 12:23:00 -05:00
|
|
|
)
|
|
|
|
|
2017-04-03 11:00:23 -04:00
|
|
|
// Format represents an output representation, usually to a file on disk.
|
2023-01-04 12:24:36 -05:00
|
|
|
// <docsmeta>{ "name": "OutputFormat" }</docsmeta>
|
2017-04-03 11:00:23 -04:00
|
|
|
type Format struct {
|
2023-01-04 12:24:36 -05:00
|
|
|
// The Name is used as an identifier. Internal output formats (i.e. html and rss)
|
2017-04-03 11:00:23 -04:00
|
|
|
// can be overridden by providing a new definition for those types.
|
2023-01-04 12:24:36 -05:00
|
|
|
// <docsmeta>{ "identifiers": ["html", "rss"] }</docsmeta>
|
2024-01-31 03:43:02 -05:00
|
|
|
Name string `json:"-"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
2021-04-01 13:02:39 -04:00
|
|
|
MediaType media.Type `json:"-"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
|
|
|
// Must be set to a value when there are two or more conflicting mediatype for the same resource.
|
2017-07-31 10:38:02 -04:00
|
|
|
Path string `json:"path"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
|
|
|
// The base output file name used when not using "ugly URLs", defaults to "index".
|
2017-07-31 10:38:02 -04:00
|
|
|
BaseName string `json:"baseName"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
// The value to use for rel links.
|
2017-07-31 10:38:02 -04:00
|
|
|
Rel string `json:"rel"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
|
|
|
// The protocol to use, i.e. "webcal://". Defaults to the protocol of the baseURL.
|
2017-07-31 10:38:02 -04:00
|
|
|
Protocol string `json:"protocol"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
|
|
|
// IsPlainText decides whether to use text/template or html/template
|
|
|
|
// as template parser.
|
2017-07-31 10:38:02 -04:00
|
|
|
IsPlainText bool `json:"isPlainText"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
|
|
|
// IsHTML returns whether this format is int the HTML family. This includes
|
|
|
|
// HTML, AMP etc. This is used to decide when to create alias redirects etc.
|
2017-07-31 10:38:02 -04:00
|
|
|
IsHTML bool `json:"isHTML"`
|
2017-04-03 11:00:23 -04:00
|
|
|
|
|
|
|
// Enable to ignore the global uglyURLs setting.
|
2017-07-31 10:38:02 -04:00
|
|
|
NoUgly bool `json:"noUgly"`
|
2017-04-08 05:15:28 -04:00
|
|
|
|
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
|
|
|
// Enable to override the global uglyURLs setting.
|
|
|
|
Ugly bool `json:"ugly"`
|
|
|
|
|
2017-04-08 05:15:28 -04:00
|
|
|
// Enable if it doesn't make sense to include this format in an alternative
|
|
|
|
// format listing, CSS being one good example.
|
|
|
|
// Note that we use the term "alternative" and not "alternate" here, as it
|
|
|
|
// does not necessarily replace the other format, it is an alternative representation.
|
2017-07-31 10:38:02 -04:00
|
|
|
NotAlternative bool `json:"notAlternative"`
|
2019-01-02 06:33:26 -05:00
|
|
|
|
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
|
|
|
// Eneable if this is a resource which path always starts at the root,
|
|
|
|
// e.g. /robots.txt.
|
|
|
|
Root bool `json:"root"`
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Setting this will make this output format control the value of
|
|
|
|
// .Permalink and .RelPermalink for a rendered Page.
|
|
|
|
// If not set, these values will point to the main (first) output format
|
|
|
|
// configured. That is probably the behaviour you want in most situations,
|
|
|
|
// as you probably don't want to link back to the RSS version of a page, as an
|
|
|
|
// example. AMP would, however, be a good example of an output format where this
|
|
|
|
// behaviour is wanted.
|
2019-03-28 15:59:09 -04:00
|
|
|
Permalinkable bool `json:"permalinkable"`
|
2019-05-02 03:54:26 -04:00
|
|
|
|
|
|
|
// Setting this to a non-zero value will be used as the first sort criteria.
|
|
|
|
Weight int `json:"weight"`
|
2017-04-03 11:00:23 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// Built-in output formats.
|
2017-03-05 12:23:00 -05:00
|
|
|
var (
|
2017-03-25 14:36:50 -04:00
|
|
|
AMPFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "amp",
|
|
|
|
MediaType: media.Builtin.HTMLType,
|
2019-01-02 06:33:26 -05:00
|
|
|
BaseName: "index",
|
|
|
|
Path: "amp",
|
|
|
|
Rel: "amphtml",
|
|
|
|
IsHTML: true,
|
|
|
|
Permalinkable: true,
|
2018-09-06 18:00:19 -04:00
|
|
|
// See https://www.ampproject.org/learn/overview/
|
2017-03-08 07:45:33 -05:00
|
|
|
}
|
|
|
|
|
2017-03-25 14:36:50 -04:00
|
|
|
CalendarFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "calendar",
|
|
|
|
MediaType: media.Builtin.CalendarType,
|
2017-03-23 12:31:05 -04:00
|
|
|
IsPlainText: true,
|
|
|
|
Protocol: "webcal://",
|
|
|
|
BaseName: "index",
|
|
|
|
Rel: "alternate",
|
|
|
|
}
|
|
|
|
|
2017-03-25 14:36:50 -04:00
|
|
|
CSSFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "css",
|
|
|
|
MediaType: media.Builtin.CSSType,
|
2017-04-08 05:15:28 -04:00
|
|
|
BaseName: "styles",
|
|
|
|
IsPlainText: true,
|
|
|
|
Rel: "stylesheet",
|
|
|
|
NotAlternative: true,
|
2017-04-01 09:12:31 -04:00
|
|
|
}
|
|
|
|
CSVFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "csv",
|
|
|
|
MediaType: media.Builtin.CSVType,
|
2017-04-01 09:12:31 -04:00
|
|
|
BaseName: "index",
|
|
|
|
IsPlainText: true,
|
|
|
|
Rel: "alternate",
|
2017-03-08 07:45:33 -05:00
|
|
|
}
|
|
|
|
|
2017-03-25 14:36:50 -04:00
|
|
|
HTMLFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "html",
|
|
|
|
MediaType: media.Builtin.HTMLType,
|
2019-01-02 06:33:26 -05:00
|
|
|
BaseName: "index",
|
|
|
|
Rel: "canonical",
|
|
|
|
IsHTML: true,
|
|
|
|
Permalinkable: true,
|
2019-05-02 03:54:26 -04:00
|
|
|
|
|
|
|
// Weight will be used as first sort criteria. HTML will, by default,
|
|
|
|
// be rendered first, but set it to 10 so it's easy to put one above it.
|
|
|
|
Weight: 10,
|
2017-03-05 12:23:00 -05:00
|
|
|
}
|
|
|
|
|
2022-05-27 09:19:02 -04:00
|
|
|
MarkdownFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "markdown",
|
|
|
|
MediaType: media.Builtin.MarkdownType,
|
2022-05-27 09:19:02 -04:00
|
|
|
BaseName: "index",
|
|
|
|
Rel: "alternate",
|
|
|
|
IsPlainText: true,
|
|
|
|
}
|
|
|
|
|
2017-03-25 14:36:50 -04:00
|
|
|
JSONFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "json",
|
|
|
|
MediaType: media.Builtin.JSONType,
|
2017-03-08 07:45:33 -05:00
|
|
|
BaseName: "index",
|
|
|
|
IsPlainText: true,
|
2017-03-22 04:54:56 -04:00
|
|
|
Rel: "alternate",
|
2017-03-08 07:45:33 -05:00
|
|
|
}
|
|
|
|
|
2021-06-09 19:13:46 -04:00
|
|
|
WebAppManifestFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "webappmanifest",
|
|
|
|
MediaType: media.Builtin.WebAppManifestType,
|
2021-06-18 07:19:37 -04:00
|
|
|
BaseName: "manifest",
|
|
|
|
IsPlainText: true,
|
|
|
|
NotAlternative: true,
|
|
|
|
Rel: "manifest",
|
2021-06-09 19:13:46 -04:00
|
|
|
}
|
|
|
|
|
2018-01-25 04:36:53 -05:00
|
|
|
RobotsTxtFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "robots",
|
|
|
|
MediaType: media.Builtin.TextType,
|
2018-01-25 04:36:53 -05:00
|
|
|
BaseName: "robots",
|
|
|
|
IsPlainText: true,
|
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
|
|
|
Root: true,
|
2018-01-25 04:36:53 -05:00
|
|
|
Rel: "alternate",
|
|
|
|
}
|
|
|
|
|
2017-03-25 14:36:50 -04:00
|
|
|
RSSFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "rss",
|
|
|
|
MediaType: media.Builtin.RSSType,
|
2017-03-07 08:20:39 -05:00
|
|
|
BaseName: "index",
|
2017-03-09 13:19:29 -05:00
|
|
|
NoUgly: true,
|
2017-03-22 04:54:56 -04:00
|
|
|
Rel: "alternate",
|
2017-03-05 12:23:00 -05:00
|
|
|
}
|
2018-03-10 05:45:29 -05:00
|
|
|
|
|
|
|
SitemapFormat = Format{
|
2023-01-04 12:24:36 -05:00
|
|
|
Name: "sitemap",
|
|
|
|
MediaType: media.Builtin.XMLType,
|
2018-03-10 05:45:29 -05:00
|
|
|
BaseName: "sitemap",
|
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
|
|
|
Ugly: true,
|
2018-03-10 05:45:29 -05:00
|
|
|
Rel: "sitemap",
|
|
|
|
}
|
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
|
|
|
|
|
|
|
SitemapIndexFormat = Format{
|
|
|
|
Name: "sitemapindex",
|
|
|
|
MediaType: media.Builtin.XMLType,
|
|
|
|
BaseName: "sitemap",
|
|
|
|
Ugly: true,
|
|
|
|
Root: true,
|
|
|
|
Rel: "sitemap",
|
|
|
|
}
|
|
|
|
|
|
|
|
HTTPStatusHTMLFormat = Format{
|
|
|
|
Name: "httpstatus",
|
|
|
|
MediaType: media.Builtin.HTMLType,
|
|
|
|
NotAlternative: true,
|
|
|
|
Ugly: true,
|
|
|
|
IsHTML: true,
|
|
|
|
Permalinkable: true,
|
|
|
|
}
|
2017-03-05 12:23:00 -05:00
|
|
|
)
|
|
|
|
|
2018-09-06 18:00:19 -04:00
|
|
|
// DefaultFormats contains the default output formats supported by Hugo.
|
2017-04-03 11:00:23 -04:00
|
|
|
var DefaultFormats = Formats{
|
|
|
|
AMPFormat,
|
|
|
|
CalendarFormat,
|
|
|
|
CSSFormat,
|
|
|
|
CSVFormat,
|
|
|
|
HTMLFormat,
|
|
|
|
JSONFormat,
|
2022-05-27 09:19:02 -04:00
|
|
|
MarkdownFormat,
|
2021-06-09 19:13:46 -04:00
|
|
|
WebAppManifestFormat,
|
2018-03-10 05:45:29 -05:00
|
|
|
RobotsTxtFormat,
|
2017-04-03 11:00:23 -04:00
|
|
|
RSSFormat,
|
2018-03-10 05:45:29 -05:00
|
|
|
SitemapFormat,
|
2017-04-03 11:00:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
sort.Sort(DefaultFormats)
|
2017-03-08 07:45:33 -05:00
|
|
|
}
|
|
|
|
|
2018-09-06 18:00:19 -04:00
|
|
|
// Formats is a slice of Format.
|
2023-01-04 12:24:36 -05:00
|
|
|
// <docsmeta>{ "name": "OutputFormats" }</docsmeta>
|
2017-03-16 03:32:14 -04:00
|
|
|
type Formats []Format
|
2017-03-06 07:40:06 -05:00
|
|
|
|
2019-05-02 03:54:26 -04:00
|
|
|
func (formats Formats) Len() int { return len(formats) }
|
|
|
|
func (formats Formats) Swap(i, j int) { formats[i], formats[j] = formats[j], formats[i] }
|
|
|
|
func (formats Formats) Less(i, j int) bool {
|
|
|
|
fi, fj := formats[i], formats[j]
|
|
|
|
if fi.Weight == fj.Weight {
|
|
|
|
return fi.Name < fj.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
if fj.Weight == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return fi.Weight > 0 && fi.Weight < fj.Weight
|
|
|
|
}
|
2017-04-03 11:00:23 -04:00
|
|
|
|
|
|
|
// GetBySuffix gets a output format given as suffix, e.g. "html".
|
|
|
|
// It will return false if no format could be found, or if the suffix given
|
|
|
|
// is ambiguous.
|
|
|
|
// The lookup is case insensitive.
|
|
|
|
func (formats Formats) GetBySuffix(suffix string) (f Format, found bool) {
|
2017-03-24 11:54:37 -04:00
|
|
|
for _, ff := range formats {
|
2021-03-11 03:18:01 -05:00
|
|
|
for _, suffix2 := range ff.MediaType.Suffixes() {
|
|
|
|
if strings.EqualFold(suffix, suffix2) {
|
|
|
|
if found {
|
|
|
|
// ambiguous
|
|
|
|
found = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f = ff
|
|
|
|
found = true
|
2017-04-03 11:00:23 -04:00
|
|
|
}
|
2017-03-24 11:54:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-04-03 11:00:23 -04:00
|
|
|
// GetByName gets a format by its identifier name.
|
|
|
|
func (formats Formats) GetByName(name string) (f Format, found bool) {
|
2017-03-27 14:43:49 -04:00
|
|
|
for _, ff := range formats {
|
2017-04-03 11:00:23 -04:00
|
|
|
if strings.EqualFold(name, ff.Name) {
|
2017-03-27 14:43:49 -04:00
|
|
|
f = ff
|
|
|
|
found = true
|
2017-04-03 11:00:23 -04:00
|
|
|
return
|
2017-03-27 14:43:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-04-03 11:00:23 -04:00
|
|
|
// GetByNames gets a list of formats given a list of identifiers.
|
|
|
|
func (formats Formats) GetByNames(names ...string) (Formats, error) {
|
|
|
|
var types []Format
|
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
tpe, ok := formats.GetByName(name)
|
|
|
|
if !ok {
|
|
|
|
return types, fmt.Errorf("OutputFormat with key %q not found", name)
|
|
|
|
}
|
|
|
|
types = append(types, tpe)
|
|
|
|
}
|
|
|
|
return types, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromFilename gets a Format given a filename.
|
2017-03-27 14:43:49 -04:00
|
|
|
func (formats Formats) FromFilename(filename string) (f Format, found bool) {
|
|
|
|
// mytemplate.amp.html
|
|
|
|
// mytemplate.html
|
|
|
|
// mytemplate
|
|
|
|
var ext, outFormat string
|
|
|
|
|
|
|
|
parts := strings.Split(filename, ".")
|
|
|
|
if len(parts) > 2 {
|
|
|
|
outFormat = parts[1]
|
|
|
|
ext = parts[2]
|
|
|
|
} else if len(parts) > 1 {
|
|
|
|
ext = parts[1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if outFormat != "" {
|
|
|
|
return formats.GetByName(outFormat)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ext != "" {
|
2017-06-20 11:20:08 -04:00
|
|
|
f, found = formats.GetBySuffix(ext)
|
|
|
|
if !found && len(parts) == 2 {
|
|
|
|
// For extensionless output formats (e.g. Netlify's _redirects)
|
|
|
|
// we must fall back to using the extension as format lookup.
|
|
|
|
f, found = formats.GetByName(ext)
|
|
|
|
}
|
2017-03-27 14:43:49 -04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-06 21:40:37 -04:00
|
|
|
// BaseFilename returns the base filename of f including an extension (ie.
|
|
|
|
// "index.xml").
|
|
|
|
func (f Format) BaseFilename() string {
|
2021-03-11 03:18:01 -05:00
|
|
|
return f.BaseName + f.MediaType.FirstSuffix.FullSuffix
|
2017-04-05 10:18:53 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// IsZero returns true if f represents a zero value.
|
|
|
|
func (f Format) IsZero() bool {
|
|
|
|
return f.Name == ""
|
|
|
|
}
|
|
|
|
|
2018-09-06 21:40:37 -04:00
|
|
|
// MarshalJSON returns the JSON encoding of f.
|
2022-12-30 03:20:58 -05:00
|
|
|
// For internal use only.
|
2018-09-06 21:40:37 -04:00
|
|
|
func (f Format) MarshalJSON() ([]byte, error) {
|
2017-04-05 10:18:53 -04:00
|
|
|
type Alias Format
|
|
|
|
return json.Marshal(&struct {
|
2021-04-01 13:02:39 -04:00
|
|
|
MediaType string `json:"mediaType"`
|
2017-04-05 10:18:53 -04:00
|
|
|
Alias
|
|
|
|
}{
|
2018-09-06 21:40:37 -04:00
|
|
|
MediaType: f.MediaType.String(),
|
|
|
|
Alias: (Alias)(f),
|
2017-04-05 10:18:53 -04:00
|
|
|
})
|
2017-03-09 13:19:29 -05:00
|
|
|
}
|