2017-01-10 04:55:03 -05:00
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
2020-12-02 07:23:25 -05:00
|
|
|
"bytes"
|
2023-02-11 10:20:24 -05:00
|
|
|
"context"
|
2020-12-02 07:23:25 -05:00
|
|
|
"fmt"
|
2019-09-03 04:36:09 -04:00
|
|
|
"image/jpeg"
|
2019-04-23 06:33:51 -04:00
|
|
|
"io"
|
2022-02-09 10:37:21 -05:00
|
|
|
"io/fs"
|
2020-02-10 06:03:41 -05:00
|
|
|
"math/rand"
|
2020-12-02 07:23:25 -05:00
|
|
|
"os"
|
2017-01-10 04:55:03 -05:00
|
|
|
"path/filepath"
|
2020-12-02 07:23:25 -05:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
2017-01-10 04:55:03 -05:00
|
|
|
"testing"
|
2020-12-02 07:23:25 -05:00
|
|
|
"text/template"
|
2020-02-10 06:03:41 -05:00
|
|
|
"time"
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
"github.com/gohugoio/hugo/config/allconfig"
|
2021-12-12 06:11:11 -05:00
|
|
|
"github.com/gohugoio/hugo/config/security"
|
2019-09-10 05:26:34 -04:00
|
|
|
"github.com/gohugoio/hugo/htesting"
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
"github.com/gohugoio/hugo/output"
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"github.com/gohugoio/hugo/parser/metadecoders"
|
2019-08-10 15:05:17 -04:00
|
|
|
"github.com/google/go-cmp/cmp"
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/parser"
|
|
|
|
|
2019-04-10 04:11:51 -04:00
|
|
|
"github.com/fsnotify/fsnotify"
|
2021-12-12 06:11:11 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hexec"
|
2023-06-16 02:17:42 -04:00
|
|
|
"github.com/gohugoio/hugo/common/loggers"
|
2021-06-09 04:58:18 -04:00
|
|
|
"github.com/gohugoio/hugo/common/maps"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
|
|
|
"github.com/gohugoio/hugo/deps"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
|
|
|
"github.com/sanity-io/litter"
|
2017-06-13 13:07:35 -04:00
|
|
|
"github.com/spf13/afero"
|
2019-03-24 05:11:16 -04:00
|
|
|
"github.com/spf13/cast"
|
2017-02-20 03:33:35 -05:00
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/helpers"
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2019-03-24 05:11:16 -04:00
|
|
|
"github.com/gohugoio/hugo/resources/resource"
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
2019-08-10 15:05:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
deepEqualsPages = qt.CmpEquals(cmp.Comparer(func(p1, p2 *pageState) bool { return p1 == p2 }))
|
|
|
|
deepEqualsOutputFormats = qt.CmpEquals(cmp.Comparer(func(o1, o2 output.Format) bool {
|
2023-01-04 12:24:36 -05:00
|
|
|
return o1.Name == o2.Name && o1.MediaType.Type == o2.MediaType.Type
|
2019-08-10 15:05:17 -04:00
|
|
|
}))
|
2017-01-10 04:55:03 -05:00
|
|
|
)
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
type sitesBuilder struct {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
Cfg config.Provider
|
2023-01-04 12:24:36 -05:00
|
|
|
Configs *allconfig.Configs
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
environ []string
|
|
|
|
|
|
|
|
Fs *hugofs.Fs
|
|
|
|
T testing.TB
|
|
|
|
depsCfg deps.DepsCfg
|
2018-03-15 04:37:30 -04:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
*qt.C
|
2019-04-23 06:33:51 -04:00
|
|
|
|
2020-10-21 05:17:48 -04:00
|
|
|
logger loggers.Logger
|
2020-02-10 06:03:41 -05:00
|
|
|
rnd *rand.Rand
|
2018-03-18 06:07:24 -04:00
|
|
|
dumper litter.Options
|
|
|
|
|
2019-04-10 04:11:51 -04:00
|
|
|
// Used to test partial rebuilds.
|
|
|
|
changedFiles []string
|
2019-12-20 02:11:36 -05:00
|
|
|
removedFiles []string
|
2019-04-10 04:11:51 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
// Aka the Hugo server mode.
|
|
|
|
running bool
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
H *HugoSites
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
theme string
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
// Default toml
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
configFormat string
|
|
|
|
configFileSet bool
|
2021-07-14 15:47:26 -04:00
|
|
|
configSet bool
|
2018-03-16 13:27:44 -04:00
|
|
|
|
2018-03-21 12:21:46 -04:00
|
|
|
// Default is empty.
|
|
|
|
// TODO(bep) revisit this and consider always setting it to something.
|
|
|
|
// Consider this in relation to using the BaseFs.PublishFs to all publishing.
|
|
|
|
workingDir string
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
addNothing bool
|
2018-03-17 14:24:02 -04:00
|
|
|
// Base data/content
|
2020-02-10 06:03:41 -05:00
|
|
|
contentFilePairs []filenameContent
|
|
|
|
templateFilePairs []filenameContent
|
|
|
|
i18nFilePairs []filenameContent
|
|
|
|
dataFilePairs []filenameContent
|
2018-03-17 14:24:02 -04:00
|
|
|
|
|
|
|
// Additional data/content.
|
|
|
|
// As in "use the base, but add these on top".
|
2020-02-10 06:03:41 -05:00
|
|
|
contentFilePairsAdded []filenameContent
|
|
|
|
templateFilePairsAdded []filenameContent
|
|
|
|
i18nFilePairsAdded []filenameContent
|
|
|
|
dataFilePairsAdded []filenameContent
|
|
|
|
}
|
|
|
|
|
|
|
|
type filenameContent struct {
|
|
|
|
filename string
|
|
|
|
content string
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTestSitesBuilder(t testing.TB) *sitesBuilder {
|
2023-01-04 12:24:36 -05:00
|
|
|
v := config.New()
|
|
|
|
v.Set("publishDir", "public")
|
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
|
|
|
v.Set("disableLiveReload", true)
|
2023-01-04 12:24:36 -05:00
|
|
|
fs := hugofs.NewFromOld(afero.NewMemMapFs(), v)
|
2018-03-15 04:37:30 -04:00
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
litterOptions := litter.Options{
|
|
|
|
HidePrivateFields: true,
|
|
|
|
StripPackageNames: true,
|
|
|
|
Separator: " ",
|
|
|
|
}
|
|
|
|
|
2020-12-02 07:23:25 -05:00
|
|
|
return &sitesBuilder{
|
|
|
|
T: t, C: qt.New(t), Fs: fs, configFormat: "toml",
|
|
|
|
dumper: litterOptions, rnd: rand.New(rand.NewSource(time.Now().Unix())),
|
|
|
|
}
|
2018-03-16 13:27:44 -04:00
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
func newTestSitesBuilderFromDepsCfg(t testing.TB, d deps.DepsCfg) *sitesBuilder {
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
2018-07-20 09:02:35 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
litterOptions := litter.Options{
|
|
|
|
HidePrivateFields: true,
|
|
|
|
StripPackageNames: true,
|
|
|
|
Separator: " ",
|
2018-07-20 09:02:35 -04:00
|
|
|
}
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
2020-02-10 06:03:41 -05:00
|
|
|
b := &sitesBuilder{T: t, C: c, depsCfg: d, Fs: d.Fs, dumper: litterOptions, rnd: rand.New(rand.NewSource(time.Now().Unix()))}
|
2023-01-04 12:24:36 -05:00
|
|
|
workingDir := d.Configs.LoadingInfo.BaseConfig.WorkingDir
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
b.WithWorkingDir(workingDir)
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
return b
|
2018-07-20 09:02:35 -04:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func (s *sitesBuilder) Running() *sitesBuilder {
|
|
|
|
s.running = true
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
func (s *sitesBuilder) WithNothingAdded() *sitesBuilder {
|
|
|
|
s.addNothing = true
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2020-10-21 05:17:48 -04:00
|
|
|
func (s *sitesBuilder) WithLogger(logger loggers.Logger) *sitesBuilder {
|
2018-05-08 04:10:13 -04:00
|
|
|
s.logger = logger
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2018-03-21 12:21:46 -04:00
|
|
|
func (s *sitesBuilder) WithWorkingDir(dir string) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.workingDir = filepath.FromSlash(dir)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithEnviron(env ...string) *sitesBuilder {
|
|
|
|
for i := 0; i < len(env); i += 2 {
|
|
|
|
s.environ = append(s.environ, fmt.Sprintf("%s=%s", env[i], env[i+1]))
|
|
|
|
}
|
2018-03-21 12:21:46 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *sitesBuilder) WithConfigTemplate(data any, format, configTemplate string) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
if format == "" {
|
|
|
|
format = "toml"
|
|
|
|
}
|
|
|
|
|
|
|
|
templ, err := template.New("test").Parse(configTemplate)
|
|
|
|
if err != nil {
|
2018-03-17 14:24:02 -04:00
|
|
|
s.Fatalf("Template parse failed: %s", err)
|
2018-03-16 13:27:44 -04:00
|
|
|
}
|
|
|
|
var b bytes.Buffer
|
|
|
|
templ.Execute(&b, data)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s.WithConfigFile(format, b.String())
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
|
2021-06-09 04:58:18 -04:00
|
|
|
func (s *sitesBuilder) WithViper(v config.Provider) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
|
|
|
if s.configFileSet {
|
|
|
|
s.T.Fatal("WithViper: use Viper or config.toml, not both")
|
|
|
|
}
|
|
|
|
defer func() {
|
2021-06-09 04:58:18 -04:00
|
|
|
s.configSet = true
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}()
|
2018-08-05 05:13:49 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
// Write to a config file to make sure the tests follow the same code path.
|
|
|
|
var buff bytes.Buffer
|
2021-06-09 04:58:18 -04:00
|
|
|
m := v.Get("").(maps.Params)
|
2019-08-10 15:05:17 -04:00
|
|
|
s.Assert(parser.InterfaceToConfig(m, metadecoders.TOML, &buff), qt.IsNil)
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
return s.WithConfigFile("toml", buff.String())
|
2018-03-17 14:24:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithConfigFile(format, conf string) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2021-06-09 04:58:18 -04:00
|
|
|
if s.configSet {
|
|
|
|
s.T.Fatal("WithConfigFile: use config.Config or config.toml, not both")
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}
|
|
|
|
s.configFileSet = true
|
|
|
|
filename := s.absFilename("config." + format)
|
|
|
|
writeSource(s.T, s.Fs, filename, conf)
|
2018-03-16 13:27:44 -04:00
|
|
|
s.configFormat = format
|
2018-03-15 04:37:30 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
func (s *sitesBuilder) WithThemeConfigFile(format, conf string) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2018-03-18 06:07:24 -04:00
|
|
|
if s.theme == "" {
|
|
|
|
s.theme = "test-theme"
|
|
|
|
}
|
|
|
|
filename := filepath.Join("themes", s.theme, "config."+format)
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
writeSource(s.T, s.Fs, s.absFilename(filename), conf)
|
2018-03-18 06:07:24 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
func (s *sitesBuilder) WithSourceFile(filenameContent ...string) *sitesBuilder {
|
|
|
|
s.T.Helper()
|
|
|
|
for i := 0; i < len(filenameContent); i += 2 {
|
|
|
|
writeSource(s.T, s.Fs, s.absFilename(filenameContent[i]), filenameContent[i+1])
|
|
|
|
}
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
func (s *sitesBuilder) absFilename(filename string) string {
|
|
|
|
filename = filepath.FromSlash(filename)
|
2020-01-22 05:57:23 -05:00
|
|
|
if filepath.IsAbs(filename) {
|
|
|
|
return filename
|
|
|
|
}
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
if s.workingDir != "" && !strings.HasPrefix(filename, s.workingDir) {
|
|
|
|
filename = filepath.Join(s.workingDir, filename)
|
|
|
|
}
|
|
|
|
return filename
|
|
|
|
}
|
|
|
|
|
2018-05-23 04:03:11 -04:00
|
|
|
const commonConfigSections = `
|
|
|
|
|
|
|
|
[services]
|
|
|
|
[services.disqus]
|
|
|
|
shortname = "disqus_shortname"
|
|
|
|
[services.googleAnalytics]
|
2021-03-03 07:30:06 -05:00
|
|
|
id = "UA-ga_id"
|
2018-05-23 04:03:11 -04:00
|
|
|
|
2018-05-25 04:53:39 -04:00
|
|
|
[privacy]
|
|
|
|
[privacy.disqus]
|
|
|
|
disable = false
|
|
|
|
[privacy.googleAnalytics]
|
|
|
|
respectDoNotTrack = true
|
|
|
|
[privacy.instagram]
|
|
|
|
simple = true
|
|
|
|
[privacy.twitter]
|
|
|
|
enableDNT = true
|
|
|
|
[privacy.vimeo]
|
|
|
|
disable = false
|
|
|
|
[privacy.youtube]
|
|
|
|
disable = false
|
|
|
|
privacyEnhanced = true
|
|
|
|
|
2018-05-23 04:03:11 -04:00
|
|
|
`
|
|
|
|
|
2018-03-17 14:24:02 -04:00
|
|
|
func (s *sitesBuilder) WithSimpleConfigFile() *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2018-11-15 01:21:14 -05:00
|
|
|
return s.WithSimpleConfigFileAndBaseURL("http://example.com/")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithSimpleConfigFileAndBaseURL(baseURL string) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2022-03-17 17:03:27 -04:00
|
|
|
return s.WithSimpleConfigFileAndSettings(map[string]any{"baseURL": baseURL})
|
2020-06-14 05:14:56 -04:00
|
|
|
}
|
2018-05-23 04:03:11 -04:00
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *sitesBuilder) WithSimpleConfigFileAndSettings(settings any) *sitesBuilder {
|
2020-06-14 05:14:56 -04:00
|
|
|
s.T.Helper()
|
|
|
|
var buf bytes.Buffer
|
|
|
|
parser.InterfaceToConfig(settings, metadecoders.TOML, &buf)
|
|
|
|
config := buf.String() + commonConfigSections
|
2018-03-17 14:24:02 -04:00
|
|
|
return s.WithConfigFile("toml", config)
|
|
|
|
}
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
func (s *sitesBuilder) WithDefaultMultiSiteConfig() *sitesBuilder {
|
2020-12-02 07:23:25 -05:00
|
|
|
defaultMultiSiteConfig := `
|
2018-03-15 04:37:30 -04:00
|
|
|
baseURL = "http://example.com/blog"
|
|
|
|
|
|
|
|
disablePathToLower = true
|
|
|
|
defaultContentLanguage = "en"
|
|
|
|
defaultContentLanguageInSubdir = true
|
|
|
|
|
2024-09-28 16:15:53 -04:00
|
|
|
[pagination]
|
|
|
|
pagerSize = 1
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
[permalinks]
|
|
|
|
other = "/somewhere/else/:filename"
|
|
|
|
|
|
|
|
[Taxonomies]
|
|
|
|
tag = "tags"
|
|
|
|
|
|
|
|
[Languages]
|
|
|
|
[Languages.en]
|
|
|
|
weight = 10
|
|
|
|
title = "In English"
|
|
|
|
languageName = "English"
|
|
|
|
[[Languages.en.menu.main]]
|
|
|
|
url = "/"
|
|
|
|
name = "Home"
|
|
|
|
weight = 0
|
|
|
|
|
|
|
|
[Languages.fr]
|
|
|
|
weight = 20
|
|
|
|
title = "Le Français"
|
|
|
|
languageName = "Français"
|
|
|
|
[Languages.fr.Taxonomies]
|
|
|
|
plaque = "plaques"
|
|
|
|
|
|
|
|
[Languages.nn]
|
|
|
|
weight = 30
|
|
|
|
title = "På nynorsk"
|
|
|
|
languageName = "Nynorsk"
|
2024-09-28 16:15:53 -04:00
|
|
|
[Languages.nn.pagination]
|
|
|
|
path = "side"
|
2018-03-15 04:37:30 -04:00
|
|
|
[Languages.nn.Taxonomies]
|
|
|
|
lag = "lag"
|
|
|
|
[[Languages.nn.menu.main]]
|
|
|
|
url = "/"
|
|
|
|
name = "Heim"
|
|
|
|
weight = 1
|
|
|
|
|
|
|
|
[Languages.nb]
|
|
|
|
weight = 40
|
|
|
|
title = "På bokmål"
|
|
|
|
languageName = "Bokmål"
|
2024-09-28 16:15:53 -04:00
|
|
|
[Languages.nb.pagination]
|
|
|
|
path = "side"
|
2018-03-15 04:37:30 -04:00
|
|
|
[Languages.nb.Taxonomies]
|
|
|
|
lag = "lag"
|
2018-05-23 04:03:11 -04:00
|
|
|
` + commonConfigSections
|
2018-03-15 04:37:30 -04:00
|
|
|
|
2018-03-17 14:24:02 -04:00
|
|
|
return s.WithConfigFile("toml", defaultMultiSiteConfig)
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
|
2019-04-23 06:33:51 -04:00
|
|
|
func (s *sitesBuilder) WithSunset(in string) {
|
|
|
|
// Write a real image into one of the bundle above.
|
|
|
|
src, err := os.Open(filepath.FromSlash("testdata/sunset.jpg"))
|
2019-08-10 15:05:17 -04:00
|
|
|
s.Assert(err, qt.IsNil)
|
2019-04-23 06:33:51 -04:00
|
|
|
|
2019-09-03 04:36:09 -04:00
|
|
|
out, err := s.Fs.Source.Create(filepath.FromSlash(filepath.Join(s.workingDir, in)))
|
2019-08-10 15:05:17 -04:00
|
|
|
s.Assert(err, qt.IsNil)
|
2019-04-23 06:33:51 -04:00
|
|
|
|
|
|
|
_, err = io.Copy(out, src)
|
2019-08-10 15:05:17 -04:00
|
|
|
s.Assert(err, qt.IsNil)
|
2019-04-23 06:33:51 -04:00
|
|
|
|
|
|
|
out.Close()
|
|
|
|
src.Close()
|
|
|
|
}
|
|
|
|
|
2020-02-10 06:03:41 -05:00
|
|
|
func (s *sitesBuilder) createFilenameContent(pairs []string) []filenameContent {
|
|
|
|
var slice []filenameContent
|
|
|
|
s.appendFilenameContent(&slice, pairs...)
|
|
|
|
return slice
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) appendFilenameContent(slice *[]filenameContent, pairs ...string) {
|
|
|
|
if len(pairs)%2 != 0 {
|
|
|
|
panic("file content mismatch")
|
|
|
|
}
|
|
|
|
for i := 0; i < len(pairs); i += 2 {
|
|
|
|
c := filenameContent{
|
|
|
|
filename: pairs[i],
|
|
|
|
content: pairs[i+1],
|
|
|
|
}
|
|
|
|
*slice = append(*slice, c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
func (s *sitesBuilder) WithContent(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.contentFilePairs, filenameContent...)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s
|
2018-03-16 13:27:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithContentAdded(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.contentFilePairsAdded, filenameContent...)
|
2018-03-15 04:37:30 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithTemplates(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.templateFilePairs, filenameContent...)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s
|
2018-03-16 13:27:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithTemplatesAdded(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.templateFilePairsAdded, filenameContent...)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithData(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.dataFilePairs, filenameContent...)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithDataAdded(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.dataFilePairsAdded, filenameContent...)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithI18n(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.i18nFilePairs, filenameContent...)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) WithI18nAdded(filenameContent ...string) *sitesBuilder {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.appendFilenameContent(&s.i18nFilePairsAdded, filenameContent...)
|
2018-03-17 14:24:02 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2019-04-10 04:11:51 -04:00
|
|
|
func (s *sitesBuilder) EditFiles(filenameContent ...string) *sitesBuilder {
|
|
|
|
for i := 0; i < len(filenameContent); i += 2 {
|
|
|
|
filename, content := filepath.FromSlash(filenameContent[i]), filenameContent[i+1]
|
2019-11-27 07:42:36 -05:00
|
|
|
absFilename := s.absFilename(filename)
|
2019-12-20 02:11:36 -05:00
|
|
|
s.changedFiles = append(s.changedFiles, absFilename)
|
2019-11-27 07:42:36 -05:00
|
|
|
writeSource(s.T, s.Fs, absFilename, content)
|
2019-04-10 04:11:51 -04:00
|
|
|
|
|
|
|
}
|
2019-12-20 02:11:36 -05:00
|
|
|
return s
|
|
|
|
}
|
2019-04-10 04:11:51 -04:00
|
|
|
|
2019-12-20 02:11:36 -05:00
|
|
|
func (s *sitesBuilder) RemoveFiles(filenames ...string) *sitesBuilder {
|
|
|
|
for _, filename := range filenames {
|
|
|
|
absFilename := s.absFilename(filename)
|
|
|
|
s.removedFiles = append(s.removedFiles, absFilename)
|
|
|
|
s.Assert(s.Fs.Source.Remove(absFilename), qt.IsNil)
|
|
|
|
}
|
2019-04-10 04:11:51 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2020-02-10 06:03:41 -05:00
|
|
|
func (s *sitesBuilder) writeFilePairs(folder string, files []filenameContent) *sitesBuilder {
|
|
|
|
// We have had some "filesystem ordering" bugs that we have not discovered in
|
|
|
|
// our tests running with the in memory filesystem.
|
|
|
|
// That file system is backed by a map so not sure how this helps, but some
|
|
|
|
// randomness in tests doesn't hurt.
|
2020-02-28 08:22:05 -05:00
|
|
|
// TODO(bep) this turns out to be more confusing than helpful.
|
2020-12-02 07:23:25 -05:00
|
|
|
// s.rnd.Shuffle(len(files), func(i, j int) { files[i], files[j] = files[j], files[i] })
|
2020-02-10 06:03:41 -05:00
|
|
|
|
|
|
|
for _, fc := range files {
|
2018-03-21 12:21:46 -04:00
|
|
|
target := folder
|
|
|
|
// TODO(bep) clean up this magic.
|
2020-02-10 06:03:41 -05:00
|
|
|
if strings.HasPrefix(fc.filename, folder) {
|
2018-03-21 12:21:46 -04:00
|
|
|
target = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.workingDir != "" {
|
|
|
|
target = filepath.Join(s.workingDir, target)
|
|
|
|
}
|
|
|
|
|
2020-02-10 06:03:41 -05:00
|
|
|
writeSource(s.T, s.Fs, filepath.Join(target, fc.filename), fc.content)
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) CreateSites() *sitesBuilder {
|
2018-10-03 08:58:09 -04:00
|
|
|
if err := s.CreateSitesE(); err != nil {
|
|
|
|
s.Fatalf("Failed to create sites: %s", err)
|
|
|
|
}
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
s.Assert(s.Fs.PublishDir, qt.IsNotNil)
|
|
|
|
s.Assert(s.Fs.WorkingDirReadOnly, qt.IsNotNil)
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2018-11-15 03:28:02 -05:00
|
|
|
func (s *sitesBuilder) LoadConfig() error {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
if !s.configFileSet {
|
|
|
|
s.WithSimpleConfigFile()
|
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
flags := config.New()
|
|
|
|
flags.Set("internal", map[string]any{
|
|
|
|
"running": s.running,
|
2023-05-24 03:26:30 -04:00
|
|
|
"watch": s.running,
|
2023-01-04 12:24:36 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
if s.workingDir != "" {
|
|
|
|
flags.Set("workingDir", s.workingDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{
|
|
|
|
Fs: s.Fs.Source,
|
|
|
|
Logger: s.logger,
|
|
|
|
Flags: flags,
|
|
|
|
Environ: s.environ,
|
|
|
|
Filename: "config." + s.configFormat,
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
})
|
2018-11-15 03:28:02 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
s.Cfg = res.LoadingInfo.Cfg
|
|
|
|
s.Configs = res
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
2018-11-15 03:28:02 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
func (s *sitesBuilder) CreateSitesE() error {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
if !s.addNothing {
|
|
|
|
if _, ok := s.Fs.Source.(*afero.OsFs); ok {
|
|
|
|
for _, dir := range []string{
|
|
|
|
"content/sect",
|
|
|
|
"layouts/_default",
|
2020-01-05 06:56:41 -05:00
|
|
|
"layouts/_default/_markup",
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"layouts/partials",
|
|
|
|
"layouts/shortcodes",
|
|
|
|
"data",
|
|
|
|
"i18n",
|
|
|
|
} {
|
2023-12-18 11:41:15 -05:00
|
|
|
if err := os.MkdirAll(filepath.Join(s.workingDir, dir), 0o777); err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return fmt.Errorf("failed to create %q: %w", dir, err)
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}
|
|
|
|
}
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
s.addDefaults()
|
|
|
|
s.writeFilePairs("content", s.contentFilePairsAdded)
|
|
|
|
s.writeFilePairs("layouts", s.templateFilePairsAdded)
|
|
|
|
s.writeFilePairs("data", s.dataFilePairsAdded)
|
|
|
|
s.writeFilePairs("i18n", s.i18nFilePairsAdded)
|
|
|
|
|
|
|
|
s.writeFilePairs("i18n", s.i18nFilePairs)
|
|
|
|
s.writeFilePairs("data", s.dataFilePairs)
|
|
|
|
s.writeFilePairs("content", s.contentFilePairs)
|
|
|
|
s.writeFilePairs("layouts", s.templateFilePairs)
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
if err := s.LoadConfig(); err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return fmt.Errorf("failed to load config: %w", err)
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
s.Fs.PublishDir = hugofs.NewCreateCountingFs(s.Fs.PublishDir)
|
2019-09-06 03:28:43 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
depsCfg := s.depsCfg
|
|
|
|
depsCfg.Fs = s.Fs
|
2023-01-04 12:24:36 -05:00
|
|
|
if depsCfg.Configs.IsZero() {
|
|
|
|
depsCfg.Configs = s.Configs
|
|
|
|
}
|
2023-06-16 02:17:42 -04:00
|
|
|
depsCfg.TestLogger = s.logger
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
sites, err := NewHugoSites(depsCfg)
|
2018-03-15 04:37:30 -04:00
|
|
|
if err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return fmt.Errorf("failed to create sites: %w", err)
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
s.H = sites
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) BuildE(cfg BuildCfg) error {
|
|
|
|
if s.H == nil {
|
|
|
|
s.CreateSites()
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.H.Build(cfg)
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) Build(cfg BuildCfg) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2018-03-24 04:19:49 -04:00
|
|
|
return s.build(cfg, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *sitesBuilder) BuildFail(cfg BuildCfg) *sitesBuilder {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2018-03-24 04:19:49 -04:00
|
|
|
return s.build(cfg, true)
|
|
|
|
}
|
|
|
|
|
2019-04-10 04:11:51 -04:00
|
|
|
func (s *sitesBuilder) changeEvents() []fsnotify.Event {
|
2019-12-20 02:11:36 -05:00
|
|
|
var events []fsnotify.Event
|
|
|
|
|
|
|
|
for _, v := range s.changedFiles {
|
|
|
|
events = append(events, fsnotify.Event{
|
2019-04-10 04:11:51 -04:00
|
|
|
Name: v,
|
|
|
|
Op: fsnotify.Write,
|
2019-12-20 02:11:36 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
for _, v := range s.removedFiles {
|
|
|
|
events = append(events, fsnotify.Event{
|
|
|
|
Name: v,
|
|
|
|
Op: fsnotify.Remove,
|
|
|
|
})
|
2019-04-10 04:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return events
|
|
|
|
}
|
|
|
|
|
2018-03-24 04:19:49 -04:00
|
|
|
func (s *sitesBuilder) build(cfg BuildCfg, shouldFail bool) *sitesBuilder {
|
2019-08-18 05:21:27 -04:00
|
|
|
s.Helper()
|
2019-04-10 04:11:51 -04:00
|
|
|
defer func() {
|
|
|
|
s.changedFiles = nil
|
|
|
|
}()
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
if s.H == nil {
|
2018-03-17 14:24:02 -04:00
|
|
|
s.CreateSites()
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
|
2019-04-10 04:11:51 -04:00
|
|
|
err := s.H.Build(cfg, s.changeEvents()...)
|
2018-10-03 08:58:09 -04:00
|
|
|
|
2018-05-23 04:03:11 -04:00
|
|
|
if err == nil {
|
|
|
|
logErrorCount := s.H.NumLogErrors()
|
|
|
|
if logErrorCount > 0 {
|
|
|
|
err = fmt.Errorf("logged %d errors", logErrorCount)
|
|
|
|
}
|
|
|
|
}
|
2018-03-24 04:19:49 -04:00
|
|
|
if err != nil && !shouldFail {
|
2018-03-17 14:24:02 -04:00
|
|
|
s.Fatalf("Build failed: %s", err)
|
2018-03-24 04:19:49 -04:00
|
|
|
} else if err == nil && shouldFail {
|
|
|
|
s.Fatalf("Expected error")
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2018-03-17 14:24:02 -04:00
|
|
|
func (s *sitesBuilder) addDefaults() {
|
|
|
|
var (
|
|
|
|
contentTemplate = `---
|
2018-03-15 04:37:30 -04:00
|
|
|
title: doc1
|
|
|
|
weight: 1
|
|
|
|
tags:
|
|
|
|
- tag1
|
|
|
|
date: "2018-02-28"
|
|
|
|
---
|
|
|
|
# doc1
|
|
|
|
*some "content"*
|
|
|
|
{{< shortcode >}}
|
|
|
|
{{< lingo >}}
|
|
|
|
`
|
|
|
|
|
2018-03-17 14:24:02 -04:00
|
|
|
defaultContent = []string{
|
|
|
|
"content/sect/doc1.en.md", contentTemplate,
|
|
|
|
"content/sect/doc1.fr.md", contentTemplate,
|
|
|
|
"content/sect/doc1.nb.md", contentTemplate,
|
|
|
|
"content/sect/doc1.nn.md", contentTemplate,
|
|
|
|
}
|
|
|
|
|
2019-10-28 05:52:47 -04:00
|
|
|
listTemplateCommon = "{{ $p := .Paginator }}{{ $p.PageNumber }}|{{ .Title }}|{{ i18n \"hello\" }}|{{ .Permalink }}|Pager: {{ template \"_internal/pagination.html\" . }}|Kind: {{ .Kind }}|Content: {{ .Content }}|Len Pages: {{ len .Pages }}|Len RegularPages: {{ len .RegularPages }}| HasParent: {{ if .Parent }}YES{{ else }}NO{{ end }}"
|
2018-12-29 04:35:46 -05:00
|
|
|
|
2018-03-17 14:24:02 -04:00
|
|
|
defaultTemplates = []string{
|
2019-10-28 05:52:47 -04:00
|
|
|
"_default/single.html", "Single: {{ .Title }}|{{ i18n \"hello\" }}|{{.Language.Lang}}|RelPermalink: {{ .RelPermalink }}|Permalink: {{ .Permalink }}|{{ .Content }}|Resources: {{ range .Resources }}{{ .MediaType }}: {{ .RelPermalink}} -- {{ end }}|Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|Parent: {{ .Parent.Title }}",
|
2018-12-29 04:35:46 -05:00
|
|
|
"_default/list.html", "List Page " + listTemplateCommon,
|
2023-01-04 12:24:36 -05:00
|
|
|
"index.html", "{{ $p := .Paginator }}Default Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}|String Resource Permalink: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").Permalink }}",
|
|
|
|
"index.fr.html", "{{ $p := .Paginator }}French Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}|String Resource Permalink: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").Permalink }}",
|
2018-12-29 04:35:46 -05:00
|
|
|
"_default/terms.html", "Taxonomy Term Page " + listTemplateCommon,
|
|
|
|
"_default/taxonomy.html", "Taxonomy List Page " + listTemplateCommon,
|
2018-03-17 14:24:02 -04:00
|
|
|
// Shortcodes
|
|
|
|
"shortcodes/shortcode.html", "Shortcode: {{ i18n \"hello\" }}",
|
|
|
|
// A shortcode in multiple languages
|
|
|
|
"shortcodes/lingo.html", "LingoDefault",
|
|
|
|
"shortcodes/lingo.fr.html", "LingoFrench",
|
2019-01-02 06:33:26 -05:00
|
|
|
// Special templates
|
|
|
|
"404.html", "404|{{ .Lang }}|{{ .Title }}",
|
|
|
|
"robots.txt", "robots|{{ .Lang }}|{{ .Title }}",
|
2018-03-17 14:24:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultI18n = []string{
|
|
|
|
"en.yaml", `
|
|
|
|
hello:
|
|
|
|
other: "Hello"
|
|
|
|
`,
|
|
|
|
"fr.yaml", `
|
|
|
|
hello:
|
|
|
|
other: "Bonjour"
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultData = []string{
|
|
|
|
"hugo.toml", "slogan = \"Hugo Rocks!\"",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(s.contentFilePairs) == 0 {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.writeFilePairs("content", s.createFilenameContent(defaultContent))
|
2018-03-17 14:24:02 -04:00
|
|
|
}
|
2020-02-10 06:03:41 -05:00
|
|
|
|
2018-03-17 14:24:02 -04:00
|
|
|
if len(s.templateFilePairs) == 0 {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.writeFilePairs("layouts", s.createFilenameContent(defaultTemplates))
|
2018-03-17 14:24:02 -04:00
|
|
|
}
|
|
|
|
if len(s.dataFilePairs) == 0 {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.writeFilePairs("data", s.createFilenameContent(defaultData))
|
2018-03-17 14:24:02 -04:00
|
|
|
}
|
|
|
|
if len(s.i18nFilePairs) == 0 {
|
2020-02-10 06:03:41 -05:00
|
|
|
s.writeFilePairs("i18n", s.createFilenameContent(defaultI18n))
|
2018-03-17 14:24:02 -04:00
|
|
|
}
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *sitesBuilder) Fatalf(format string, args ...any) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
|
|
|
s.T.Fatalf(format, args...)
|
2018-03-16 13:27:44 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *sitesBuilder) AssertFileContentFn(filename string, f func(s string) bool) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2019-01-02 06:33:26 -05:00
|
|
|
content := s.FileContent(filename)
|
|
|
|
if !f(content) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.Fatalf("Assert failed for %q in content\n%s", filename, content)
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-09 10:37:21 -05:00
|
|
|
// Helper to migrate tests to new format.
|
|
|
|
func (s *sitesBuilder) DumpTxtar() string {
|
|
|
|
var sb strings.Builder
|
|
|
|
|
|
|
|
skipRe := regexp.MustCompile(`^(public|resources|package-lock.json|go.sum)`)
|
|
|
|
|
|
|
|
afero.Walk(s.Fs.Source, s.workingDir, func(path string, info fs.FileInfo, err error) 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
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-02-09 10:37:21 -05:00
|
|
|
rel := strings.TrimPrefix(path, s.workingDir+"/")
|
|
|
|
if skipRe.MatchString(rel) {
|
|
|
|
if info.IsDir() {
|
|
|
|
return filepath.SkipDir
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if info == nil || info.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
sb.WriteString(fmt.Sprintf("-- %s --\n", rel))
|
|
|
|
b, err := afero.ReadFile(s.Fs.Source, path)
|
|
|
|
s.Assert(err, qt.IsNil)
|
|
|
|
sb.WriteString(strings.TrimSpace(string(b)))
|
|
|
|
sb.WriteString("\n")
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
return sb.String()
|
|
|
|
}
|
|
|
|
|
2019-05-31 03:40:58 -04:00
|
|
|
func (s *sitesBuilder) AssertHome(matches ...string) {
|
|
|
|
s.AssertFileContent("public/index.html", matches...)
|
|
|
|
}
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
func (s *sitesBuilder) AssertFileContent(filename string, matches ...string) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2019-01-02 06:33:26 -05:00
|
|
|
content := s.FileContent(filename)
|
2019-08-09 04:05:22 -04:00
|
|
|
for _, m := range matches {
|
|
|
|
lines := strings.Split(m, "\n")
|
|
|
|
for _, match := range lines {
|
|
|
|
match = strings.TrimSpace(match)
|
|
|
|
if match == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !strings.Contains(content, match) {
|
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
|
|
|
s.Assert(content, qt.Contains, match, qt.Commentf(match+" not in: \n"+content))
|
2019-08-09 04:05:22 -04:00
|
|
|
}
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 09:00:25 -04:00
|
|
|
func (s *sitesBuilder) AssertFileDoesNotExist(filename string) {
|
|
|
|
if s.CheckExists(filename) {
|
|
|
|
s.Fatalf("File %q exists but must not exist.", filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 04:36:09 -04:00
|
|
|
func (s *sitesBuilder) AssertImage(width, height int, filename string) {
|
2022-03-21 04:35:15 -04:00
|
|
|
f, err := s.Fs.WorkingDirReadOnly.Open(filename)
|
2019-09-03 04:36:09 -04:00
|
|
|
s.Assert(err, qt.IsNil)
|
|
|
|
defer f.Close()
|
|
|
|
cfg, err := jpeg.DecodeConfig(f)
|
2020-01-15 09:59:56 -05:00
|
|
|
s.Assert(err, qt.IsNil)
|
2019-09-03 04:36:09 -04:00
|
|
|
s.Assert(cfg.Width, qt.Equals, width)
|
|
|
|
s.Assert(cfg.Height, qt.Equals, height)
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:28:43 -04:00
|
|
|
func (s *sitesBuilder) AssertNoDuplicateWrites() {
|
|
|
|
s.Helper()
|
2022-09-14 05:58:45 -04:00
|
|
|
hugofs.WalkFilesystems(s.Fs.PublishDir, func(fs afero.Fs) bool {
|
|
|
|
if dfs, ok := fs.(hugofs.DuplicatesReporter); ok {
|
|
|
|
s.Assert(dfs.ReportDuplicates(), qt.Equals, "")
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
2019-09-06 03:28:43 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *sitesBuilder) FileContent(filename string) string {
|
2022-03-21 04:35:15 -04:00
|
|
|
s.Helper()
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
filename = filepath.FromSlash(filename)
|
2022-03-21 04:35:15 -04:00
|
|
|
return readWorkingDir(s.T, s.Fs, filename)
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *sitesBuilder) AssertObject(expected string, object any) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s.T.Helper()
|
2018-03-18 06:07:24 -04:00
|
|
|
got := s.dumper.Sdump(object)
|
|
|
|
expected = strings.TrimSpace(expected)
|
|
|
|
|
|
|
|
if expected != got {
|
|
|
|
fmt.Println(got)
|
2019-09-10 05:26:34 -04:00
|
|
|
diff := htesting.DiffStrings(expected, got)
|
2018-03-18 06:07:24 -04:00
|
|
|
s.Fatalf("diff:\n%s\nexpected\n%s\ngot\n%s", diff, expected, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 04:37:30 -04:00
|
|
|
func (s *sitesBuilder) AssertFileContentRe(filename string, matches ...string) {
|
2022-03-21 04:35:15 -04:00
|
|
|
content := readWorkingDir(s.T, s.Fs, filename)
|
2018-03-15 04:37:30 -04:00
|
|
|
for _, match := range matches {
|
2019-01-02 06:33:26 -05:00
|
|
|
r := regexp.MustCompile("(?s)" + match)
|
2018-03-15 04:37:30 -04:00
|
|
|
if !r.MatchString(content) {
|
2018-03-16 13:27:44 -04:00
|
|
|
s.Fatalf("No match for %q in content for %s\n%q", match, filename, content)
|
2018-03-15 04:37:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 14:24:02 -04:00
|
|
|
func (s *sitesBuilder) CheckExists(filename string) bool {
|
2022-03-21 04:35:15 -04:00
|
|
|
return workingDirExists(s.Fs, filepath.Clean(filename))
|
2018-03-17 14:24:02 -04:00
|
|
|
}
|
2020-01-22 05:57:23 -05:00
|
|
|
|
|
|
|
func (s *sitesBuilder) GetPage(ref string) page.Page {
|
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
|
|
|
p, err := s.H.Sites[0].getPage(nil, ref)
|
2020-01-22 05:57:23 -05:00
|
|
|
s.Assert(err, qt.IsNil)
|
|
|
|
return p
|
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
|
|
|
|
func (s *sitesBuilder) GetPageRel(p page.Page, ref string) page.Page {
|
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
|
|
|
p, err := s.H.Sites[0].getPage(p, ref)
|
2019-09-10 05:26:34 -04:00
|
|
|
s.Assert(err, qt.IsNil)
|
|
|
|
return p
|
|
|
|
}
|
2018-03-17 14:24:02 -04:00
|
|
|
|
2021-12-12 06:11:11 -05:00
|
|
|
func (s *sitesBuilder) NpmInstall() hexec.Runner {
|
|
|
|
sc := security.DefaultConfig
|
2023-06-28 02:56:35 -04:00
|
|
|
var err error
|
|
|
|
sc.Exec.Allow, err = security.NewWhitelist("npm")
|
|
|
|
s.Assert(err, qt.IsNil)
|
2024-06-23 06:49:10 -04:00
|
|
|
ex := hexec.New(sc, s.workingDir)
|
2021-12-12 06:11:11 -05:00
|
|
|
command, err := ex.New("npm", "install")
|
|
|
|
s.Assert(err, qt.IsNil)
|
|
|
|
return command
|
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
func newTestHelperFromProvider(cfg config.Provider, fs *hugofs.Fs, t testing.TB) (testHelper, *allconfig.Configs) {
|
|
|
|
res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{
|
|
|
|
Flags: cfg,
|
|
|
|
Fs: fs.Source,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return newTestHelper(res.Base, fs, t), res
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestHelper(cfg *allconfig.Config, fs *hugofs.Fs, t testing.TB) testHelper {
|
2019-08-10 15:05:17 -04:00
|
|
|
return testHelper{
|
|
|
|
Cfg: cfg,
|
|
|
|
Fs: fs,
|
|
|
|
C: qt.New(t),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 14:52:50 -05:00
|
|
|
type testHelper struct {
|
2023-01-04 12:24:36 -05:00
|
|
|
Cfg *allconfig.Config
|
2017-02-17 14:52:50 -05:00
|
|
|
Fs *hugofs.Fs
|
2019-08-10 15:05:17 -04:00
|
|
|
*qt.C
|
2017-02-17 14:52:50 -05:00
|
|
|
}
|
|
|
|
|
2017-02-17 15:14:52 -05:00
|
|
|
func (th testHelper) assertFileContent(filename string, matches ...string) {
|
2019-08-10 15:05:17 -04:00
|
|
|
th.Helper()
|
2017-02-17 15:14:52 -05:00
|
|
|
filename = th.replaceDefaultContentLanguageValue(filename)
|
2022-03-21 04:35:15 -04:00
|
|
|
content := readWorkingDir(th, th.Fs, filename)
|
2017-02-17 14:52:50 -05:00
|
|
|
for _, match := range matches {
|
2017-02-17 15:14:52 -05:00
|
|
|
match = th.replaceDefaultContentLanguageValue(match)
|
2019-11-06 14:10:47 -05:00
|
|
|
th.Assert(strings.Contains(content, match), qt.Equals, true, qt.Commentf(match+" not in: \n"+content))
|
2017-02-17 14:52:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 16:03:25 -04:00
|
|
|
func (th testHelper) assertFileNotExist(filename string) {
|
2022-03-21 04:35:15 -04:00
|
|
|
exists, err := helpers.Exists(filename, th.Fs.PublishDir)
|
2019-08-10 15:05:17 -04:00
|
|
|
th.Assert(err, qt.IsNil)
|
|
|
|
th.Assert(exists, qt.Equals, false)
|
2017-04-23 16:03:25 -04:00
|
|
|
}
|
|
|
|
|
2017-02-17 15:14:52 -05:00
|
|
|
func (th testHelper) replaceDefaultContentLanguageValue(value string) string {
|
2023-01-04 12:24:36 -05:00
|
|
|
defaultInSubDir := th.Cfg.DefaultContentLanguageInSubdir
|
|
|
|
replace := th.Cfg.DefaultContentLanguage + "/"
|
2017-02-17 15:14:52 -05:00
|
|
|
|
|
|
|
if !defaultInSubDir {
|
|
|
|
value = strings.Replace(value, replace, "", 1)
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
func loadTestConfigFromProvider(cfg config.Provider) (*allconfig.Configs, error) {
|
|
|
|
workingDir := cfg.GetString("workingDir")
|
|
|
|
fs := afero.NewMemMapFs()
|
|
|
|
if workingDir != "" {
|
2023-12-18 11:41:15 -05:00
|
|
|
fs.MkdirAll(workingDir, 0o755)
|
2023-01-04 12:24:36 -05:00
|
|
|
}
|
|
|
|
res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Flags: cfg, Fs: fs})
|
|
|
|
return res, err
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2021-06-09 04:58:18 -04:00
|
|
|
func newTestCfg(withConfig ...func(cfg config.Provider) error) (config.Provider, *hugofs.Fs) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
mm := afero.NewMemMapFs()
|
2023-01-04 12:24:36 -05:00
|
|
|
cfg := config.New()
|
2023-07-07 12:41:10 -04:00
|
|
|
cfg.Set("defaultContentLanguageInSubdir", false)
|
2023-01-04 12:24:36 -05:00
|
|
|
cfg.Set("publishDir", "public")
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
fs := hugofs.NewFromOld(hugofs.NewBaseFileDecorator(mm), cfg)
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
return cfg, fs
|
2017-02-04 22:20:06 -05:00
|
|
|
}
|
|
|
|
|
2017-03-27 14:43:49 -04:00
|
|
|
func newTestSitesFromConfig(t testing.TB, afs afero.Fs, tomlConfig string, layoutPathContentPairs ...string) (testHelper, *HugoSites) {
|
2017-02-20 03:33:35 -05:00
|
|
|
if len(layoutPathContentPairs)%2 != 0 {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
t.Fatalf("Layouts must be provided in pairs")
|
2017-02-20 03:33:35 -05:00
|
|
|
}
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c := qt.New(t)
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
writeToFs(t, afs, filepath.Join("content", ".gitkeep"), "")
|
2017-03-27 14:43:49 -04:00
|
|
|
writeToFs(t, afs, "config.toml", tomlConfig)
|
2017-02-20 03:33:35 -05:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
cfg, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Fs: afs})
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2017-02-20 03:33:35 -05:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
fs := hugofs.NewFrom(afs, cfg.LoadingInfo.BaseConfig)
|
|
|
|
th := newTestHelper(cfg.Base, fs, t)
|
2017-02-20 03:33:35 -05:00
|
|
|
|
|
|
|
for i := 0; i < len(layoutPathContentPairs); i += 2 {
|
|
|
|
writeSource(t, fs, layoutPathContentPairs[i], layoutPathContentPairs[i+1])
|
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
h, err := NewHugoSites(deps.DepsCfg{Fs: fs, Configs: cfg})
|
2017-02-20 03:33:35 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
c.Assert(err, qt.IsNil)
|
2017-02-20 03:33:35 -05:00
|
|
|
|
|
|
|
return th, h
|
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
// TODO(bep) replace these with the builder
|
2017-05-23 05:10:15 -04:00
|
|
|
func buildSingleSite(t testing.TB, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
|
2019-08-10 15:05:17 -04:00
|
|
|
t.Helper()
|
2018-10-03 08:58:09 -04:00
|
|
|
return buildSingleSiteExpected(t, false, false, depsCfg, buildCfg)
|
2017-02-04 22:20:06 -05:00
|
|
|
}
|
|
|
|
|
2020-12-16 06:11:32 -05:00
|
|
|
func buildSingleSiteExpected(t testing.TB, expectSiteInitError, expectBuildError bool, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
t.Helper()
|
|
|
|
b := newTestSitesBuilderFromDepsCfg(t, depsCfg).WithNothingAdded()
|
|
|
|
|
|
|
|
err := b.CreateSitesE()
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2020-12-16 06:11:32 -05:00
|
|
|
if expectSiteInitError {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(err, qt.Not(qt.IsNil))
|
2018-10-03 08:58:09 -04:00
|
|
|
return nil
|
|
|
|
} else {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(err, qt.IsNil)
|
2018-10-03 08:58:09 -04:00
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
h := b.H
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(len(h.Sites), qt.Equals, 1)
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
if expectBuildError {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(h.Build(buildCfg), qt.Not(qt.IsNil))
|
2017-02-04 22:20:06 -05:00
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(h.Build(buildCfg), qt.IsNil)
|
2017-01-10 04:55:03 -05:00
|
|
|
|
|
|
|
return h.Sites[0]
|
|
|
|
}
|
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
func writeSourcesToSource(t *testing.T, base string, fs *hugofs.Fs, sources ...[2]string) {
|
2017-01-10 04:55:03 -05:00
|
|
|
for _, src := range sources {
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
writeSource(t, fs, filepath.Join(base, src[0]), src[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func getPage(in page.Page, ref string) page.Page {
|
|
|
|
p, err := in.GetPage(ref)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2019-03-24 05:11:16 -04:00
|
|
|
func content(c resource.ContentProvider) string {
|
2023-02-11 10:20:24 -05:00
|
|
|
cc, err := c.Content(context.Background())
|
2019-03-24 05:11:16 -04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ccs, err := cast.ToStringE(cc)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ccs
|
|
|
|
}
|