2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2017-02-04 22:20:06 -05:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2018-10-03 08:58:09 -04:00
|
|
|
"errors"
|
2022-04-26 13:57:04 -04:00
|
|
|
"fmt"
|
2020-12-02 07:23:25 -05:00
|
|
|
"io/ioutil"
|
2022-03-18 03:54:44 -04:00
|
|
|
"net"
|
2020-12-02 07:23:25 -05:00
|
|
|
"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 03:16:58 -04:00
|
|
|
"sync"
|
2020-12-02 07:23:25 -05: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 03:16:58 -04:00
|
|
|
|
2020-03-08 11:33:15 -04: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 03:16:58 -04:00
|
|
|
"golang.org/x/sync/semaphore"
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
"github.com/gohugoio/hugo/common/herrors"
|
2022-04-26 13:57:04 -04:00
|
|
|
"github.com/gohugoio/hugo/common/htime"
|
2018-11-26 04:11:22 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hugo"
|
2022-03-21 04:35:15 -04:00
|
|
|
"github.com/gohugoio/hugo/common/paths"
|
2018-11-26 04:11:22 -05:00
|
|
|
|
2022-04-26 13:57:04 -04:00
|
|
|
"github.com/spf13/cast"
|
2018-10-03 08:58:09 -04:00
|
|
|
jww "github.com/spf13/jwalterweatherman"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/common/loggers"
|
2018-04-07 05:27:22 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/hugolib"
|
2018-10-03 08:58:09 -04:00
|
|
|
"github.com/spf13/afero"
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2022-04-26 13:57:04 -04:00
|
|
|
"github.com/bep/clock"
|
2018-04-04 03:29:59 -04:00
|
|
|
"github.com/bep/debounce"
|
2022-03-21 04:35:15 -04:00
|
|
|
"github.com/bep/overlayfs"
|
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 07:40:43 -04:00
|
|
|
"github.com/gohugoio/hugo/common/types"
|
2017-06-13 12:42:45 -04: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 09:01:25 -05:00
|
|
|
"github.com/gohugoio/hugo/langs"
|
2017-02-04 22:20:06 -05:00
|
|
|
)
|
|
|
|
|
2018-06-28 06:20:03 -04:00
|
|
|
type commandeerHugoState struct {
|
2017-02-04 22:20:06 -05:00
|
|
|
*deps.DepsCfg
|
2019-08-15 03:33:47 -04:00
|
|
|
hugoSites *hugolib.HugoSites
|
|
|
|
fsCreate sync.Once
|
|
|
|
created chan struct{}
|
2018-06-28 06:20:03 -04:00
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2018-06-28 06:20:03 -04:00
|
|
|
type commandeer struct {
|
|
|
|
*commandeerHugoState
|
|
|
|
|
2020-10-21 05:17:48 -04:00
|
|
|
logger loggers.Logger
|
2020-03-08 11:33:15 -04:00
|
|
|
serverConfig *config.Server
|
2018-10-03 08:58:09 -04:00
|
|
|
|
2022-02-10 11:12:02 -05:00
|
|
|
buildLock func() (unlock func(), err error)
|
|
|
|
|
2021-08-31 11:02:51 -04: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 04:02:14 -05: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
|
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
// We need to reuse these on server rebuilds.
|
|
|
|
publishDirFs afero.Fs
|
2022-09-29 05:37:38 -04:00
|
|
|
publishDirStaticFs afero.Fs
|
2022-03-21 04:35:15 -04:00
|
|
|
publishDirServerFs afero.Fs
|
2018-04-11 02:39:39 -04:00
|
|
|
|
2018-04-10 13:16:09 -04:00
|
|
|
h *hugoBuilderCommon
|
2018-04-10 03:19:26 -04:00
|
|
|
ftch flagsToConfigHandler
|
2018-03-18 06:07:24 -04: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 07:40:43 -04:00
|
|
|
visitedURLs *types.EvictingStringQueue
|
2017-11-12 04:03:56 -05:00
|
|
|
|
2020-02-12 18:37:49 -05:00
|
|
|
cfgInit func(c *commandeer) error
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2018-06-28 06:20:03 -04:00
|
|
|
// We watch these for changes.
|
|
|
|
configFiles []string
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2018-04-04 03:29:59 -04:00
|
|
|
// Used in cases where we get flooded with events in server mode.
|
|
|
|
debounce func(f func())
|
|
|
|
|
2022-03-18 03:54:44 -04:00
|
|
|
serverPorts []serverPortListener
|
|
|
|
|
2022-05-07 08:10:32 -04:00
|
|
|
languages langs.Languages
|
|
|
|
doLiveReload bool
|
|
|
|
renderStaticToDisk bool
|
|
|
|
fastRenderMode bool
|
|
|
|
showErrorInBrowser bool
|
|
|
|
wasError bool
|
2017-11-24 02:43:09 -05:00
|
|
|
|
2017-11-12 04:03:56 -05:00
|
|
|
configured bool
|
2018-08-16 06:30:03 -04:00
|
|
|
paused bool
|
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
|
|
|
fullRebuildSem *semaphore.Weighted
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
// Any error from the last build.
|
|
|
|
buildErr error
|
|
|
|
}
|
|
|
|
|
2022-03-18 03:54:44 -04:00
|
|
|
type serverPortListener struct {
|
|
|
|
p int
|
|
|
|
ln net.Listener
|
|
|
|
}
|
|
|
|
|
2019-08-15 03:33:47 -04:00
|
|
|
func newCommandeerHugoState() *commandeerHugoState {
|
|
|
|
return &commandeerHugoState{
|
|
|
|
created: make(chan struct{}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandeerHugoState) hugo() *hugolib.HugoSites {
|
|
|
|
<-c.created
|
|
|
|
return c.hugoSites
|
|
|
|
}
|
|
|
|
|
2022-05-15 15:01:36 -04:00
|
|
|
func (c *commandeerHugoState) hugoTry() *hugolib.HugoSites {
|
|
|
|
select {
|
|
|
|
case <-c.created:
|
|
|
|
return c.hugoSites
|
|
|
|
case <-time.After(time.Millisecond * 100):
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
func (c *commandeer) errCount() int {
|
2020-10-21 05:17:48 -04:00
|
|
|
return int(c.logger.LogCounters().ErrorCounter.Count())
|
2018-10-03 08:58:09 -04:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (c *commandeer) getErrorWithContext() any {
|
2018-10-03 08:58:09 -04:00
|
|
|
errCount := c.errCount()
|
|
|
|
|
|
|
|
if errCount == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
m := make(map[string]any)
|
2018-10-03 08:58:09 -04:00
|
|
|
|
2022-05-02 10:07:52 -04:00
|
|
|
//xwm["Error"] = errors.New(cleanErrorLog(removeErrorPrefixFromLog(c.logger.Errors())))
|
|
|
|
m["Error"] = errors.New(cleanErrorLog(removeErrorPrefixFromLog(c.logger.Errors())))
|
2018-11-26 04:11:22 -05:00
|
|
|
m["Version"] = hugo.BuildVersionString()
|
2022-05-02 10:07:52 -04:00
|
|
|
ferrors := herrors.UnwrapFileErrorsWithErrorContext(c.buildErr)
|
|
|
|
m["Files"] = ferrors
|
2018-10-03 08:58:09 -04:00
|
|
|
|
|
|
|
return m
|
2017-02-04 22:20:06 -05:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (c *commandeer) Set(key string, value any) {
|
2017-02-04 22:20:06 -05:00
|
|
|
if c.configured {
|
|
|
|
panic("commandeer cannot be changed")
|
|
|
|
}
|
|
|
|
c.Cfg.Set(key, value)
|
|
|
|
}
|
|
|
|
|
2017-03-25 14:48:28 -04:00
|
|
|
func (c *commandeer) initFs(fs *hugofs.Fs) error {
|
2022-03-21 04:35:15 -04:00
|
|
|
c.publishDirFs = fs.PublishDir
|
2022-09-29 05:37:38 -04:00
|
|
|
c.publishDirStaticFs = fs.PublishDirStatic
|
2022-03-21 04:35:15 -04:00
|
|
|
c.publishDirServerFs = fs.PublishDirServer
|
2017-03-25 14:48:28 -04: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 03:00:23 -04:00
|
|
|
|
2017-03-25 14:48:28 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-07 08:10:32 -04:00
|
|
|
func (c *commandeer) initClock(loc *time.Location) error {
|
2022-04-26 13:57:04 -04:00
|
|
|
bt := c.Cfg.GetString("clock")
|
|
|
|
if bt == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-07 08:10:32 -04:00
|
|
|
t, err := cast.StringToDateInDefaultLocation(bt, loc)
|
2022-04-26 13:57:04 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf(`failed to parse "clock" flag: %s`, err)
|
|
|
|
}
|
2022-05-07 08:10:32 -04:00
|
|
|
|
2022-04-26 13:57:04 -04:00
|
|
|
htime.Clock = clock.Start(t)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-31 11:02:51 -04:00
|
|
|
func newCommandeer(mustHaveConfigFile, failOnInitErr, running bool, h *hugoBuilderCommon, f flagsToConfigHandler, cfgInit func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) {
|
2018-04-04 03:29:59 -04: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 06:04:42 -05:00
|
|
|
rebuildDebouncer = debounce.New(4 * time.Second)
|
2018-04-04 03:29:59 -04:00
|
|
|
}
|
|
|
|
|
2019-11-21 07:07:52 -05:00
|
|
|
out := ioutil.Discard
|
|
|
|
if !h.quiet {
|
|
|
|
out = os.Stdout
|
|
|
|
}
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
c := &commandeer{
|
2018-06-28 06:20:03 -04:00
|
|
|
h: h,
|
|
|
|
ftch: f,
|
2019-08-15 03:33:47 -04:00
|
|
|
commandeerHugoState: newCommandeerHugoState(),
|
2020-02-12 18:37:49 -05:00
|
|
|
cfgInit: cfgInit,
|
2018-06-28 06:20:03 -04: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 03:16:58 -04:00
|
|
|
fullRebuildSem: semaphore.NewWeighted(1),
|
2021-08-31 11:02:51 -04:00
|
|
|
|
|
|
|
// Init state
|
|
|
|
mustHaveConfigFile: mustHaveConfigFile,
|
|
|
|
failOnInitErr: failOnInitErr,
|
|
|
|
running: running,
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
// This will be replaced later, but we need something to log to before the configuration is read.
|
2020-05-18 10:52:45 -04:00
|
|
|
logger: loggers.NewLogger(jww.LevelWarn, jww.LevelError, out, ioutil.Discard, running),
|
2018-04-04 03:29:59 -04:00
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2021-08-31 11:02:51 -04:00
|
|
|
return c, c.loadConfig()
|
2018-03-18 06:07:24 -04: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 04:02:14 -05: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 11:02:51 -04:00
|
|
|
func (c *commandeer) loadConfig() error {
|
2018-03-18 06:07:24 -04:00
|
|
|
if c.DepsCfg == nil {
|
|
|
|
c.DepsCfg = &deps.DepsCfg{}
|
|
|
|
}
|
|
|
|
|
2018-10-26 11:02:53 -04:00
|
|
|
if c.logger != nil {
|
|
|
|
// Truncate the error log if this is a reload.
|
|
|
|
c.logger.Reset()
|
|
|
|
}
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
cfg := c.DepsCfg
|
|
|
|
c.configured = false
|
2021-08-31 11:02:51 -04: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 03:00:23 -04:00
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
var dir string
|
2018-04-10 03:19:26 -04:00
|
|
|
if c.h.source != "" {
|
|
|
|
dir, _ = filepath.Abs(c.h.source)
|
2018-03-18 06:07:24 -04:00
|
|
|
} else {
|
|
|
|
dir, _ = os.Getwd()
|
|
|
|
}
|
|
|
|
|
|
|
|
var sourceFs afero.Fs = hugofs.Os
|
|
|
|
if c.DepsCfg.Fs != nil {
|
|
|
|
sourceFs = c.DepsCfg.Fs.Source
|
|
|
|
}
|
|
|
|
|
2021-08-31 11:02:51 -04:00
|
|
|
environment := c.h.getEnvironment(c.running)
|
2018-11-15 03:28:02 -05:00
|
|
|
|
2018-04-07 05:27:22 -04:00
|
|
|
doWithConfig := func(cfg config.Provider) error {
|
2018-04-10 03:19:26 -04:00
|
|
|
if c.ftch != nil {
|
|
|
|
c.ftch.flagsToConfig(cfg)
|
2018-04-07 05:27:22 -04:00
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2018-04-07 05:27:22 -04:00
|
|
|
cfg.Set("workingDir", dir)
|
2018-11-15 03:28:02 -05:00
|
|
|
cfg.Set("environment", environment)
|
2018-04-07 05:27:22 -04:00
|
|
|
return nil
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
2020-02-12 18:37:49 -05:00
|
|
|
cfgSetAndInit := func(cfg config.Provider) error {
|
2018-04-07 05:27:22 -04:00
|
|
|
c.Cfg = cfg
|
2020-02-12 18:37:49 -05:00
|
|
|
if c.cfgInit == nil {
|
2018-04-07 05:27:22 -04:00
|
|
|
return nil
|
|
|
|
}
|
2020-02-12 18:37:49 -05:00
|
|
|
err := c.cfgInit(c)
|
2018-04-07 05:27:22 -04:00
|
|
|
return err
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
2018-11-15 03:28:02 -05:00
|
|
|
configPath := c.h.source
|
|
|
|
if configPath == "" {
|
|
|
|
configPath = dir
|
|
|
|
}
|
2018-04-07 05:27:22 -04:00
|
|
|
config, configFiles, err := hugolib.LoadConfig(
|
2018-11-15 03:28:02 -05:00
|
|
|
hugolib.ConfigSourceDescriptor{
|
|
|
|
Fs: sourceFs,
|
2019-11-21 07:07:52 -05:00
|
|
|
Logger: c.logger,
|
2018-11-15 03:28:02 -05:00
|
|
|
Path: configPath,
|
|
|
|
WorkingDir: dir,
|
|
|
|
Filename: c.h.cfgFile,
|
|
|
|
AbsConfigDir: c.h.getConfigDir(dir),
|
2020-12-02 07:23:25 -05:00
|
|
|
Environment: environment,
|
|
|
|
},
|
2020-02-12 18:37:49 -05:00
|
|
|
cfgSetAndInit,
|
2018-04-07 05:27:22 -04:00
|
|
|
doWithConfig)
|
|
|
|
|
2021-07-20 12:23:09 -04:00
|
|
|
if err != nil {
|
2021-08-31 06:08:11 -04: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 11:16:34 -04:00
|
|
|
if c.mustHaveConfigFile || (c.failOnInitErr && !moduleNotFoundRe.MatchString(err.Error())) {
|
2021-08-31 06:08:11 -04:00
|
|
|
return err
|
2021-09-17 11:16:34 -04:00
|
|
|
} else {
|
|
|
|
// Just make it a warning.
|
|
|
|
c.logger.Warnln(err)
|
2021-08-31 06:08:11 -04:00
|
|
|
}
|
2021-08-31 11:02:51 -04:00
|
|
|
} else if c.mustHaveConfigFile && len(configFiles) == 0 {
|
2019-10-14 23:34:56 -04:00
|
|
|
return hugolib.ErrNoConfigFile
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
2018-04-07 05:27:22 -04:00
|
|
|
c.configFiles = configFiles
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2022-05-07 08:10:32 -04:00
|
|
|
var ok bool
|
2022-05-27 07:34:20 -04:00
|
|
|
loc := time.Local
|
2022-05-07 08:10:32 -04:00
|
|
|
c.languages, ok = c.Cfg.Get("languagesSorted").(langs.Languages)
|
2022-05-27 07:34:20 -04:00
|
|
|
if ok {
|
|
|
|
loc = langs.GetLocation(c.languages[0])
|
2022-04-26 13:57:04 -04:00
|
|
|
}
|
|
|
|
|
2022-05-27 07:34:20 -04:00
|
|
|
err = c.initClock(loc)
|
2022-05-07 08:10:32 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
// Set some commonly used flags
|
2021-08-31 11:02:51 -04:00
|
|
|
c.doLiveReload = c.running && !c.Cfg.GetBool("disableLiveReload")
|
2018-10-03 08:58:09 -04:00
|
|
|
c.fastRenderMode = c.doLiveReload && !c.Cfg.GetBool("disableFastRender")
|
|
|
|
c.showErrorInBrowser = c.doLiveReload && !c.Cfg.GetBool("disableBrowserError")
|
|
|
|
|
2018-04-07 05:27:22 -04: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 18:37:49 -05:00
|
|
|
if c.cfgInit != nil {
|
|
|
|
if err := c.cfgInit(c); err != nil {
|
2018-04-07 05:27:22 -04:00
|
|
|
return err
|
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
2021-08-31 11:02:51 -04:00
|
|
|
logger, err := c.createLogger(config)
|
2018-04-07 05:27:22 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
2018-04-07 05:27:22 -04:00
|
|
|
cfg.Logger = logger
|
2018-10-03 08:58:09 -04:00
|
|
|
c.logger = logger
|
2020-05-27 07:50:13 -04:00
|
|
|
c.serverConfig, err = hconfig.DecodeServer(cfg.Cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-07 05:27:22 -04:00
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
createMemFs := config.GetBool("renderToMemory")
|
2022-03-14 11:02:04 -04:00
|
|
|
c.renderStaticToDisk = config.GetBool("renderStaticToDisk")
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
if createMemFs {
|
2018-03-18 06:07:24 -04:00
|
|
|
// Rendering to memoryFS, publish to Root regardless of publishDir.
|
|
|
|
config.Set("publishDir", "/")
|
2022-03-21 04:35:15 -04:00
|
|
|
config.Set("publishDirStatic", "/")
|
|
|
|
} else if c.renderStaticToDisk {
|
|
|
|
// Hybrid, render dynamic content to Root.
|
|
|
|
config.Set("publishDirStatic", config.Get("publishDir"))
|
|
|
|
config.Set("publishDir", "/")
|
|
|
|
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
c.fsCreate.Do(func() {
|
2022-04-18 04:28:54 -04:00
|
|
|
// Assume both source and destination are using same filesystem.
|
|
|
|
fs := hugofs.NewFromSourceAndDestination(sourceFs, sourceFs, config)
|
2018-03-18 06:07:24 -04:00
|
|
|
|
2022-03-21 04:35:15 -04:00
|
|
|
if c.publishDirFs != nil {
|
2018-06-28 06:20:03 -04:00
|
|
|
// Need to reuse the destination on server rebuilds.
|
2022-03-21 04:35:15 -04:00
|
|
|
fs.PublishDir = c.publishDirFs
|
2022-09-29 05:37:38 -04:00
|
|
|
fs.PublishDirStatic = c.publishDirStaticFs
|
2022-03-21 04:35:15 -04:00
|
|
|
fs.PublishDirServer = c.publishDirServerFs
|
|
|
|
} else {
|
2022-04-17 04:35:01 -04:00
|
|
|
if c.renderStaticToDisk {
|
2022-04-18 04:28:54 -04:00
|
|
|
publishDirStatic := config.GetString("publishDirStatic")
|
|
|
|
workingDir := config.GetString("workingDir")
|
|
|
|
absPublishDirStatic := paths.AbsPathify(workingDir, publishDirStatic)
|
|
|
|
|
|
|
|
fs = hugofs.NewFromSourceAndDestination(sourceFs, afero.NewMemMapFs(), config)
|
|
|
|
// Writes the dynamic output to memory,
|
2022-03-21 04:35:15 -04:00
|
|
|
// while serve others directly from /public on disk.
|
2022-04-18 04:28:54 -04:00
|
|
|
dynamicFs := fs.PublishDir
|
2022-03-21 04:35:15 -04:00
|
|
|
staticFs := afero.NewBasePathFs(afero.NewOsFs(), absPublishDirStatic)
|
|
|
|
|
|
|
|
// Serve from both the static and dynamic fs,
|
|
|
|
// the first will take priority.
|
|
|
|
// THis is a read-only filesystem,
|
|
|
|
// we do all the writes to
|
|
|
|
// fs.Destination and fs.DestinationStatic.
|
|
|
|
fs.PublishDirServer = overlayfs.New(
|
|
|
|
overlayfs.Options{
|
|
|
|
Fss: []afero.Fs{
|
|
|
|
dynamicFs,
|
|
|
|
staticFs,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
fs.PublishDirStatic = staticFs
|
|
|
|
} else if createMemFs {
|
|
|
|
// Hugo writes the output to memory instead of the disk.
|
2022-04-18 04:28:54 -04:00
|
|
|
fs = hugofs.NewFromSourceAndDestination(sourceFs, afero.NewMemMapFs(), config)
|
2022-03-21 04:35:15 -04:00
|
|
|
}
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
|
|
|
|
2018-10-17 03:28:04 -04: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 04:02:14 -05: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 16:39:00 -04: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 04:02:14 -05:00
|
|
|
changeDetector.PrepareNew()
|
2022-03-21 04:35:15 -04:00
|
|
|
fs.PublishDir = hugofs.NewHashingFs(fs.PublishDir, changeDetector)
|
|
|
|
fs.PublishDirStatic = hugofs.NewHashingFs(fs.PublishDirStatic, changeDetector)
|
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 04:02:14 -05:00
|
|
|
c.changeDetector = changeDetector
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if c.Cfg.GetBool("logPathWarnings") {
|
2022-03-14 11:02:06 -04:00
|
|
|
// Note that we only care about the "dynamic creates" here,
|
|
|
|
// so skip the static fs.
|
2022-03-21 04:35:15 -04:00
|
|
|
fs.PublishDir = hugofs.NewCreateCountingFs(fs.PublishDir)
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// To debug hard-to-find path issues.
|
2020-12-02 07:23:25 -05:00
|
|
|
// fs.Destination = hugofs.NewStacktracerFs(fs.Destination, `fr/fr`)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2018-03-18 06:07:24 -04: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 09:01:25 -05:00
|
|
|
if err != nil {
|
2019-08-15 03:33:47 -04: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 09:01:25 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var h *hugolib.HugoSites
|
|
|
|
|
2021-08-31 11:02:51 -04:00
|
|
|
var createErr error
|
|
|
|
h, createErr = hugolib.NewHugoSites(*c.DepsCfg)
|
|
|
|
if h == nil || c.failOnInitErr {
|
|
|
|
err = createErr
|
|
|
|
}
|
2022-03-18 03:54:44 -04:00
|
|
|
|
2019-08-15 03:33:47 -04:00
|
|
|
c.hugoSites = h
|
2022-02-10 11:12:02 -05:00
|
|
|
// TODO(bep) improve.
|
2022-02-21 13:12:04 -05:00
|
|
|
if c.buildLock == nil && h != nil {
|
2022-02-10 11:12:02 -05:00
|
|
|
c.buildLock = h.LockBuild
|
|
|
|
}
|
2019-08-15 03:33:47 -04:00
|
|
|
close(c.created)
|
2018-03-18 06:07:24 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
cacheDir, err := helpers.GetCacheDir(sourceFs, config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-03-18 06:07:24 -04:00
|
|
|
}
|
2018-11-08 04:24:13 -05:00
|
|
|
config.Set("cacheDir", cacheDir)
|
2018-03-18 06:07:24 -04:00
|
|
|
|
|
|
|
return nil
|
2017-02-04 22:20:06 -05:00
|
|
|
}
|