2019-01-02 11:33:26 +00:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2017-02-05 03:20:06 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2018-10-03 12:58:09 +00:00
|
|
|
"bytes"
|
|
|
|
"errors"
|
2020-12-02 12:23:25 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"regexp"
|
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 07:16:58 +00:00
|
|
|
"sync"
|
2020-12-02 12:23:25 +00:00
|
|
|
"time"
|
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 07:16:58 +00:00
|
|
|
|
2020-03-08 15:33:15 +00:00
|
|
|
hconfig "github.com/gohugoio/hugo/config"
|
|
|
|
|
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 07:16:58 +00:00
|
|
|
"golang.org/x/sync/semaphore"
|
|
|
|
|
2018-11-26 09:11:22 +00:00
|
|
|
"github.com/gohugoio/hugo/common/herrors"
|
|
|
|
"github.com/gohugoio/hugo/common/hugo"
|
|
|
|
|
2018-10-03 12:58:09 +00:00
|
|
|
jww "github.com/spf13/jwalterweatherman"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/common/loggers"
|
2018-04-07 09:27:22 +00:00
|
|
|
"github.com/gohugoio/hugo/config"
|
|
|
|
|
2018-03-18 10:07:24 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/hugolib"
|
2018-10-03 12:58:09 +00:00
|
|
|
"github.com/spf13/afero"
|
2018-03-18 10:07:24 +00:00
|
|
|
|
2018-04-04 07:29:59 +00:00
|
|
|
"github.com/bep/debounce"
|
Only re-render the view(s) you're working on
Hugo already, in its server mode, support partial rebuilds. To put it simply: If you change `about.md`, only that content page is read and processed, then Hugo does some processing (taxonomies etc.) and the full site is rendered.
This commit covers the rendering part: We now only re-render the pages you work on, i.e. the last n pages you watched in the browser (which obviously also includes the page in the example above).
To be more specific: When you are running the hugo server in watch (aka. livereload) mode, and change a template or a content file, then we do a partial re-rendering of the following:
* The current content page (if it is a content change)
* The home page
* Up to the last 10 pages you visited on the site.
This should in most cases be enough, but if you navigate to something completely different, you may see stale content. Doing an edit will then refresh that page.
Note that this feature is enabled by default. To turn it off, run `hugo server --disableFastRender`.
Fixes #3962
See #1643
2017-10-14 11:40:43 +00:00
|
|
|
"github.com/gohugoio/hugo/common/types"
|
2017-06-13 16:42:45 +00:00
|
|
|
"github.com/gohugoio/hugo/deps"
|
|
|
|
"github.com/gohugoio/hugo/helpers"
|
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
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 14:01:25 +00:00
|
|
|
"github.com/gohugoio/hugo/langs"
|
2017-02-05 03:20:06 +00:00
|
|
|
)
|
|
|
|
|
2018-06-28 10:20:03 +00:00
|
|
|
type commandeerHugoState struct {
|
2017-02-05 03:20:06 +00:00
|
|
|
*deps.DepsCfg
|
2019-08-15 07:33:47 +00:00
|
|
|
hugoSites *hugolib.HugoSites
|
|
|
|
fsCreate sync.Once
|
|
|
|
created chan struct{}
|
2018-06-28 10:20:03 +00:00
|
|
|
}
|
2018-03-18 10:07:24 +00:00
|
|
|
|
2018-06-28 10:20:03 +00:00
|
|
|
type commandeer struct {
|
|
|
|
*commandeerHugoState
|
|
|
|
|
2020-10-21 09:17:48 +00:00
|
|
|
logger loggers.Logger
|
2020-03-08 15:33:15 +00:00
|
|
|
serverConfig *config.Server
|
2018-10-03 12:58:09 +00:00
|
|
|
|
2021-08-31 15:02:51 +00:00
|
|
|
// Loading state
|
|
|
|
mustHaveConfigFile bool
|
|
|
|
failOnInitErr bool
|
|
|
|
running bool
|
|
|
|
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 09:02:14 +00:00
|
|
|
// Currently only set when in "fast render mode". But it seems to
|
|
|
|
// be fast enough that we could maybe just add it for all server modes.
|
|
|
|
changeDetector *fileChangeDetector
|
|
|
|
|
2018-06-28 10:20:03 +00:00
|
|
|
// We need to reuse this on server rebuilds.
|
|
|
|
destinationFs afero.Fs
|
2018-04-11 06:39:39 +00:00
|
|
|
|
2018-04-10 17:16:09 +00:00
|
|
|
h *hugoBuilderCommon
|
2018-04-10 07:19:26 +00:00
|
|
|
ftch flagsToConfigHandler
|
2018-03-18 10:07:24 +00:00
|
|
|
|
Only re-render the view(s) you're working on
Hugo already, in its server mode, support partial rebuilds. To put it simply: If you change `about.md`, only that content page is read and processed, then Hugo does some processing (taxonomies etc.) and the full site is rendered.
This commit covers the rendering part: We now only re-render the pages you work on, i.e. the last n pages you watched in the browser (which obviously also includes the page in the example above).
To be more specific: When you are running the hugo server in watch (aka. livereload) mode, and change a template or a content file, then we do a partial re-rendering of the following:
* The current content page (if it is a content change)
* The home page
* Up to the last 10 pages you visited on the site.
This should in most cases be enough, but if you navigate to something completely different, you may see stale content. Doing an edit will then refresh that page.
Note that this feature is enabled by default. To turn it off, run `hugo server --disableFastRender`.
Fixes #3962
See #1643
2017-10-14 11:40:43 +00:00
|
|
|
visitedURLs *types.EvictingStringQueue
|
2017-11-12 09:03:56 +00:00
|
|
|
|
2020-02-12 23:37:49 +00:00
|
|
|
cfgInit func(c *commandeer) error
|
2018-03-18 10:07:24 +00:00
|
|
|
|
2018-06-28 10:20:03 +00:00
|
|
|
// We watch these for changes.
|
|
|
|
configFiles []string
|
2018-03-18 10:07:24 +00:00
|
|
|
|
2018-04-04 07:29:59 +00:00
|
|
|
// Used in cases where we get flooded with events in server mode.
|
|
|
|
debounce func(f func())
|
|
|
|
|
2018-04-07 09:27:22 +00:00
|
|
|
serverPorts []int
|
|
|
|
languagesConfigured bool
|
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 14:01:25 +00:00
|
|
|
languages langs.Languages
|
2018-10-03 12:58:09 +00:00
|
|
|
doLiveReload bool
|
|
|
|
fastRenderMode bool
|
|
|
|
showErrorInBrowser bool
|
2019-12-20 07:11:36 +00:00
|
|
|
wasError bool
|
2017-11-24 07:43:09 +00:00
|
|
|
|
2017-11-12 09:03:56 +00:00
|
|
|
configured bool
|
2018-08-16 10:30:03 +00:00
|
|
|
paused bool
|
2018-10-03 12:58:09 +00: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 07:16:58 +00:00
|
|
|
fullRebuildSem *semaphore.Weighted
|
|
|
|
|
2018-10-03 12:58:09 +00:00
|
|
|
// Any error from the last build.
|
|
|
|
buildErr error
|
|
|
|
}
|
|
|
|
|
2019-08-15 07:33:47 +00:00
|
|
|
func newCommandeerHugoState() *commandeerHugoState {
|
|
|
|
return &commandeerHugoState{
|
|
|
|
created: make(chan struct{}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandeerHugoState) hugo() *hugolib.HugoSites {
|
|
|
|
<-c.created
|
|
|
|
return c.hugoSites
|
|
|
|
}
|
|
|
|
|
2018-10-03 12:58:09 +00:00
|
|
|
func (c *commandeer) errCount() int {
|
2020-10-21 09:17:48 +00:00
|
|
|
return int(c.logger.LogCounters().ErrorCounter.Count())
|
2018-10-03 12:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandeer) getErrorWithContext() interface{} {
|
|
|
|
errCount := c.errCount()
|
|
|
|
|
|
|
|
if errCount == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
m := make(map[string]interface{})
|
|
|
|
|
2018-10-24 15:22:07 +00:00
|
|
|
m["Error"] = errors.New(removeErrorPrefixFromLog(c.logger.Errors()))
|
2018-11-26 09:11:22 +00:00
|
|
|
m["Version"] = hugo.BuildVersionString()
|
2018-10-03 12:58:09 +00:00
|
|
|
|
|
|
|
fe := herrors.UnwrapErrorWithFileContext(c.buildErr)
|
|
|
|
if fe != nil {
|
|
|
|
m["File"] = fe
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.h.verbose {
|
|
|
|
var b bytes.Buffer
|
2020-01-15 14:59:56 +00:00
|
|
|
herrors.FprintStackTraceFromErr(&b, c.buildErr)
|
2018-10-03 12:58:09 +00:00
|
|
|
m["StackTrace"] = b.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
2017-02-05 03:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandeer) Set(key string, value interface{}) {
|
|
|
|
if c.configured {
|
|
|
|
panic("commandeer cannot be changed")
|
|
|
|
}
|
|
|
|
c.Cfg.Set(key, value)
|
|
|
|
}
|
|
|
|
|
2017-03-25 18:48:28 +00:00
|
|
|
func (c *commandeer) initFs(fs *hugofs.Fs) error {
|
2018-06-28 10:20:03 +00:00
|
|
|
c.destinationFs = fs.Destination
|
2017-03-25 18:48:28 +00:00
|
|
|
c.DepsCfg.Fs = fs
|
: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 07:00:23 +00:00
|
|
|
|
2017-03-25 18:48:28 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-31 15:02:51 +00:00
|
|
|
func newCommandeer(mustHaveConfigFile, failOnInitErr, running bool, h *hugoBuilderCommon, f flagsToConfigHandler, cfgInit func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) {
|
2018-04-04 07:29:59 +00:00
|
|
|
var rebuildDebouncer func(f func())
|
|
|
|
if running {
|
|
|
|
// The time value used is tested with mass content replacements in a fairly big Hugo site.
|
|
|
|
// It is better to wait for some seconds in those cases rather than get flooded
|
|
|
|
// with rebuilds.
|
2019-02-02 11:04:42 +00:00
|
|
|
rebuildDebouncer = debounce.New(4 * time.Second)
|
2018-04-04 07:29:59 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 12:07:52 +00:00
|
|
|
out := ioutil.Discard
|
|
|
|
if !h.quiet {
|
|
|
|
out = os.Stdout
|
|
|
|
}
|
|
|
|
|
2018-03-18 10:07:24 +00:00
|
|
|
c := &commandeer{
|
2018-06-28 10:20:03 +00:00
|
|
|
h: h,
|
|
|
|
ftch: f,
|
2019-08-15 07:33:47 +00:00
|
|
|
commandeerHugoState: newCommandeerHugoState(),
|
2020-02-12 23:37:49 +00:00
|
|
|
cfgInit: cfgInit,
|
2018-06-28 10:20:03 +00:00
|
|
|
visitedURLs: types.NewEvictingStringQueue(10),
|
|
|
|
debounce: rebuildDebouncer,
|
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 07:16:58 +00:00
|
|
|
fullRebuildSem: semaphore.NewWeighted(1),
|
2021-08-31 15:02:51 +00:00
|
|
|
|
|
|
|
// Init state
|
|
|
|
mustHaveConfigFile: mustHaveConfigFile,
|
|
|
|
failOnInitErr: failOnInitErr,
|
|
|
|
running: running,
|
|
|
|
|
2018-10-03 12:58:09 +00:00
|
|
|
// This will be replaced later, but we need something to log to before the configuration is read.
|
2020-05-18 14:52:45 +00:00
|
|
|
logger: loggers.NewLogger(jww.LevelWarn, jww.LevelError, out, ioutil.Discard, running),
|
2018-04-04 07:29:59 +00:00
|
|
|
}
|
2018-03-18 10:07:24 +00:00
|
|
|
|
2021-08-31 15:02:51 +00:00
|
|
|
return c, c.loadConfig()
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
|
|
|
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 09:02:14 +00:00
|
|
|
type fileChangeDetector struct {
|
|
|
|
sync.Mutex
|
|
|
|
current map[string]string
|
|
|
|
prev map[string]string
|
|
|
|
|
|
|
|
irrelevantRe *regexp.Regexp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fileChangeDetector) OnFileClose(name, md5sum string) {
|
|
|
|
f.Lock()
|
|
|
|
defer f.Unlock()
|
|
|
|
f.current[name] = md5sum
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fileChangeDetector) changed() []string {
|
|
|
|
if f == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
f.Lock()
|
|
|
|
defer f.Unlock()
|
|
|
|
var c []string
|
|
|
|
for k, v := range f.current {
|
|
|
|
vv, found := f.prev[k]
|
|
|
|
if !found || v != vv {
|
|
|
|
c = append(c, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return f.filterIrrelevant(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fileChangeDetector) filterIrrelevant(in []string) []string {
|
|
|
|
var filtered []string
|
|
|
|
for _, v := range in {
|
|
|
|
if !f.irrelevantRe.MatchString(v) {
|
|
|
|
filtered = append(filtered, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filtered
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fileChangeDetector) PrepareNew() {
|
|
|
|
if f == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f.Lock()
|
|
|
|
defer f.Unlock()
|
|
|
|
|
|
|
|
if f.current == nil {
|
|
|
|
f.current = make(map[string]string)
|
|
|
|
f.prev = make(map[string]string)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f.prev = make(map[string]string)
|
|
|
|
for k, v := range f.current {
|
|
|
|
f.prev[k] = v
|
|
|
|
}
|
|
|
|
f.current = make(map[string]string)
|
|
|
|
}
|
|
|
|
|
2021-08-31 15:02:51 +00:00
|
|
|
func (c *commandeer) loadConfig() error {
|
2018-03-18 10:07:24 +00:00
|
|
|
if c.DepsCfg == nil {
|
|
|
|
c.DepsCfg = &deps.DepsCfg{}
|
|
|
|
}
|
|
|
|
|
2018-10-26 15:02:53 +00:00
|
|
|
if c.logger != nil {
|
|
|
|
// Truncate the error log if this is a reload.
|
|
|
|
c.logger.Reset()
|
|
|
|
}
|
|
|
|
|
2018-03-18 10:07:24 +00:00
|
|
|
cfg := c.DepsCfg
|
|
|
|
c.configured = false
|
2021-08-31 15:02:51 +00:00
|
|
|
cfg.Running = c.running
|
: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 07:00:23 +00:00
|
|
|
|
2018-03-18 10:07:24 +00:00
|
|
|
var dir string
|
2018-04-10 07:19:26 +00:00
|
|
|
if c.h.source != "" {
|
|
|
|
dir, _ = filepath.Abs(c.h.source)
|
2018-03-18 10:07:24 +00:00
|
|
|
} else {
|
|
|
|
dir, _ = os.Getwd()
|
|
|
|
}
|
|
|
|
|
|
|
|
var sourceFs afero.Fs = hugofs.Os
|
|
|
|
if c.DepsCfg.Fs != nil {
|
|
|
|
sourceFs = c.DepsCfg.Fs.Source
|
|
|
|
}
|
|
|
|
|
2021-08-31 15:02:51 +00:00
|
|
|
environment := c.h.getEnvironment(c.running)
|
2018-11-15 08:28:02 +00:00
|
|
|
|
2018-04-07 09:27:22 +00:00
|
|
|
doWithConfig := func(cfg config.Provider) error {
|
2018-04-10 07:19:26 +00:00
|
|
|
if c.ftch != nil {
|
|
|
|
c.ftch.flagsToConfig(cfg)
|
2018-04-07 09:27:22 +00:00
|
|
|
}
|
2018-03-18 10:07:24 +00:00
|
|
|
|
2018-04-07 09:27:22 +00:00
|
|
|
cfg.Set("workingDir", dir)
|
2018-11-15 08:28:02 +00:00
|
|
|
cfg.Set("environment", environment)
|
2018-04-07 09:27:22 +00:00
|
|
|
return nil
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 23:37:49 +00:00
|
|
|
cfgSetAndInit := func(cfg config.Provider) error {
|
2018-04-07 09:27:22 +00:00
|
|
|
c.Cfg = cfg
|
2020-02-12 23:37:49 +00:00
|
|
|
if c.cfgInit == nil {
|
2018-04-07 09:27:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-02-12 23:37:49 +00:00
|
|
|
err := c.cfgInit(c)
|
2018-04-07 09:27:22 +00:00
|
|
|
return err
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 08:28:02 +00:00
|
|
|
configPath := c.h.source
|
|
|
|
if configPath == "" {
|
|
|
|
configPath = dir
|
|
|
|
}
|
2018-04-07 09:27:22 +00:00
|
|
|
config, configFiles, err := hugolib.LoadConfig(
|
2018-11-15 08:28:02 +00:00
|
|
|
hugolib.ConfigSourceDescriptor{
|
|
|
|
Fs: sourceFs,
|
2019-11-21 12:07:52 +00:00
|
|
|
Logger: c.logger,
|
2018-11-15 08:28:02 +00:00
|
|
|
Path: configPath,
|
|
|
|
WorkingDir: dir,
|
|
|
|
Filename: c.h.cfgFile,
|
|
|
|
AbsConfigDir: c.h.getConfigDir(dir),
|
2020-12-02 12:23:25 +00:00
|
|
|
Environment: environment,
|
|
|
|
},
|
2020-02-12 23:37:49 +00:00
|
|
|
cfgSetAndInit,
|
2018-04-07 09:27:22 +00:00
|
|
|
doWithConfig)
|
|
|
|
|
2021-07-20 16:23:09 +00:00
|
|
|
if err != nil {
|
2021-08-31 10:08:11 +00:00
|
|
|
// We should improve the error handling here,
|
|
|
|
// but with hugo mod init and similar there is a chicken and egg situation
|
|
|
|
// with modules already configured in config.toml, so ignore those errors.
|
2021-09-17 15:16:34 +00:00
|
|
|
if c.mustHaveConfigFile || (c.failOnInitErr && !moduleNotFoundRe.MatchString(err.Error())) {
|
2021-08-31 10:08:11 +00:00
|
|
|
return err
|
2021-09-17 15:16:34 +00:00
|
|
|
} else {
|
|
|
|
// Just make it a warning.
|
|
|
|
c.logger.Warnln(err)
|
2021-08-31 10:08:11 +00:00
|
|
|
}
|
2021-08-31 15:02:51 +00:00
|
|
|
} else if c.mustHaveConfigFile && len(configFiles) == 0 {
|
2019-10-15 03:34:56 +00:00
|
|
|
return hugolib.ErrNoConfigFile
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 09:27:22 +00:00
|
|
|
c.configFiles = configFiles
|
2018-03-18 10:07:24 +00: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 14:01:25 +00:00
|
|
|
if l, ok := c.Cfg.Get("languagesSorted").(langs.Languages); ok {
|
2018-04-07 09:27:22 +00:00
|
|
|
c.languagesConfigured = true
|
|
|
|
c.languages = l
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 12:58:09 +00:00
|
|
|
// Set some commonly used flags
|
2021-08-31 15:02:51 +00:00
|
|
|
c.doLiveReload = c.running && !c.Cfg.GetBool("disableLiveReload")
|
2018-10-03 12:58:09 +00:00
|
|
|
c.fastRenderMode = c.doLiveReload && !c.Cfg.GetBool("disableFastRender")
|
|
|
|
c.showErrorInBrowser = c.doLiveReload && !c.Cfg.GetBool("disableBrowserError")
|
|
|
|
|
2018-04-07 09:27:22 +00:00
|
|
|
// This is potentially double work, but we need to do this one more time now
|
|
|
|
// that all the languages have been configured.
|
2020-02-12 23:37:49 +00:00
|
|
|
if c.cfgInit != nil {
|
|
|
|
if err := c.cfgInit(c); err != nil {
|
2018-04-07 09:27:22 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 15:02:51 +00:00
|
|
|
logger, err := c.createLogger(config)
|
2018-04-07 09:27:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 09:27:22 +00:00
|
|
|
cfg.Logger = logger
|
2018-10-03 12:58:09 +00:00
|
|
|
c.logger = logger
|
2020-05-27 11:50:13 +00:00
|
|
|
c.serverConfig, err = hconfig.DecodeServer(cfg.Cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-07 09:27:22 +00:00
|
|
|
|
2018-03-18 10:07:24 +00:00
|
|
|
createMemFs := config.GetBool("renderToMemory")
|
|
|
|
|
|
|
|
if createMemFs {
|
|
|
|
// Rendering to memoryFS, publish to Root regardless of publishDir.
|
|
|
|
config.Set("publishDir", "/")
|
|
|
|
}
|
|
|
|
|
|
|
|
c.fsCreate.Do(func() {
|
|
|
|
fs := hugofs.NewFrom(sourceFs, config)
|
|
|
|
|
2018-06-28 10:20:03 +00:00
|
|
|
if c.destinationFs != nil {
|
|
|
|
// Need to reuse the destination on server rebuilds.
|
|
|
|
fs.Destination = c.destinationFs
|
|
|
|
} else if createMemFs {
|
|
|
|
// Hugo writes the output to memory instead of the disk.
|
2018-03-18 10:07:24 +00:00
|
|
|
fs.Destination = new(afero.MemMapFs)
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:28:04 +00:00
|
|
|
if c.fastRenderMode {
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 09:02:14 +00:00
|
|
|
// For now, fast render mode only. It should, however, be fast enough
|
|
|
|
// for the full variant, too.
|
|
|
|
changeDetector := &fileChangeDetector{
|
|
|
|
// We use this detector to decide to do a Hot reload of a single path or not.
|
|
|
|
// We need to filter out source maps and possibly some other to be able
|
|
|
|
// to make that decision.
|
|
|
|
irrelevantRe: regexp.MustCompile(`\.map$`),
|
|
|
|
}
|
2019-03-14 20:39:00 +00:00
|
|
|
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 09:02:14 +00:00
|
|
|
changeDetector.PrepareNew()
|
|
|
|
fs.Destination = hugofs.NewHashingFs(fs.Destination, changeDetector)
|
|
|
|
c.changeDetector = changeDetector
|
|
|
|
}
|
|
|
|
|
2019-01-02 11:33:26 +00:00
|
|
|
if c.Cfg.GetBool("logPathWarnings") {
|
|
|
|
fs.Destination = hugofs.NewCreateCountingFs(fs.Destination)
|
|
|
|
}
|
|
|
|
|
|
|
|
// To debug hard-to-find path issues.
|
2020-12-02 12:23:25 +00:00
|
|
|
// fs.Destination = hugofs.NewStacktracerFs(fs.Destination, `fr/fr`)
|
2019-01-02 11:33:26 +00:00
|
|
|
|
2018-03-18 10:07:24 +00:00
|
|
|
err = c.initFs(fs)
|
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 14:01:25 +00:00
|
|
|
if err != nil {
|
2019-08-15 07:33:47 +00:00
|
|
|
close(c.created)
|
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 14:01:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var h *hugolib.HugoSites
|
|
|
|
|
2021-08-31 15:02:51 +00:00
|
|
|
var createErr error
|
|
|
|
h, createErr = hugolib.NewHugoSites(*c.DepsCfg)
|
|
|
|
if h == nil || c.failOnInitErr {
|
|
|
|
err = createErr
|
|
|
|
}
|
2019-08-15 07:33:47 +00:00
|
|
|
c.hugoSites = h
|
|
|
|
close(c.created)
|
2018-03-18 10:07:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-11-08 09:24:13 +00:00
|
|
|
cacheDir, err := helpers.GetCacheDir(sourceFs, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-03-18 10:07:24 +00:00
|
|
|
}
|
2018-11-08 09:24:13 +00:00
|
|
|
config.Set("cacheDir", cacheDir)
|
2018-03-18 10:07:24 +00:00
|
|
|
|
|
|
|
return nil
|
2017-02-05 03:20:06 +00:00
|
|
|
}
|