2017-01-10 04:55:03 -05:00
|
|
|
package deps
|
|
|
|
|
|
|
|
import (
|
2022-05-02 10:07:52 -04:00
|
|
|
"fmt"
|
2022-09-26 11:34:20 -04:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2018-07-11 13:23:22 -04:00
|
|
|
"sync"
|
2020-02-25 15:40:02 -05:00
|
|
|
"sync/atomic"
|
2018-04-19 12:06:40 -04:00
|
|
|
"time"
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
"github.com/gohugoio/hugo/cache/filecache"
|
2021-12-12 06:11:11 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hexec"
|
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
|
|
|
"github.com/gohugoio/hugo/common/loggers"
|
2023-01-24 14:57:15 -05:00
|
|
|
"github.com/gohugoio/hugo/common/types"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
2021-12-12 06:11:11 -05:00
|
|
|
"github.com/gohugoio/hugo/config/security"
|
2017-06-13 12:42:45 -04:00
|
|
|
"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"
|
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
|
|
|
"github.com/gohugoio/hugo/media"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
2022-09-14 05:58:45 -04:00
|
|
|
"github.com/gohugoio/hugo/resources/postpub"
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2017-09-26 14:03:04 -04:00
|
|
|
"github.com/gohugoio/hugo/metrics"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/output"
|
2019-01-02 05:58:32 -05:00
|
|
|
"github.com/gohugoio/hugo/resources"
|
: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
|
|
|
"github.com/gohugoio/hugo/source"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/tpl"
|
2020-10-21 05:17:48 -04:00
|
|
|
"github.com/spf13/cast"
|
2018-10-21 06:20:21 -04:00
|
|
|
jww "github.com/spf13/jwalterweatherman"
|
2017-01-10 04:55:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Deps holds dependencies used by many.
|
2017-08-02 08:25:05 -04:00
|
|
|
// There will be normally only one instance of deps in play
|
2017-01-10 04:55:03 -05:00
|
|
|
// at a given time, i.e. one per Site built.
|
|
|
|
type Deps struct {
|
2018-07-11 13:23:22 -04:00
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// The logger to use.
|
2020-10-21 05:17:48 -04:00
|
|
|
Log loggers.Logger `json:"-"`
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2018-05-23 04:03:11 -04:00
|
|
|
// Used to log errors that may repeat itself many times.
|
2021-06-07 10:36:48 -04:00
|
|
|
LogDistinct loggers.Logger
|
2019-03-25 13:18:34 -04:00
|
|
|
|
2021-12-12 06:11:11 -05:00
|
|
|
ExecHelper *hexec.Exec
|
|
|
|
|
2019-12-10 13:56:44 -05:00
|
|
|
// The templates to use. This will usually implement the full tpl.TemplateManager.
|
2020-01-15 09:59:56 -05:00
|
|
|
tmpl tpl.TemplateHandler
|
2017-01-10 04:55:03 -05: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
|
|
|
// We use this to parse and execute ad-hoc text templates.
|
2020-01-15 09:59:56 -05:00
|
|
|
textTmpl tpl.TemplateParseFinder
|
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
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// The file systems to use.
|
|
|
|
Fs *hugofs.Fs `json:"-"`
|
|
|
|
|
|
|
|
// The PathSpec to use
|
|
|
|
*helpers.PathSpec `json:"-"`
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// The ContentSpec to use
|
|
|
|
*helpers.ContentSpec `json:"-"`
|
|
|
|
|
: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
|
|
|
// The SourceSpec to use
|
|
|
|
SourceSpec *source.SourceSpec `json:"-"`
|
|
|
|
|
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
|
|
|
// The Resource Spec to use
|
2019-01-02 05:58:32 -05:00
|
|
|
ResourceSpec *resources.Spec
|
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
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// The configuration to use
|
|
|
|
Cfg config.Provider `json:"-"`
|
|
|
|
|
2018-11-08 04:24:13 -05:00
|
|
|
// The file cache to use.
|
|
|
|
FileCaches filecache.Caches
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// The translation func to use
|
2022-03-17 17:03:27 -04:00
|
|
|
Translate func(translationID string, templateData any) string `json:"-"`
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
// The language in use. TODO(bep) consolidate with site
|
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
|
|
|
Language *langs.Language
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
// The site building.
|
2019-01-02 06:33:26 -05:00
|
|
|
Site page.Site
|
2018-11-26 04:11:22 -05:00
|
|
|
|
2017-04-04 08:10:20 -04:00
|
|
|
// All the output formats available for the current site.
|
|
|
|
OutputFormatsConfig output.Formats
|
|
|
|
|
2022-09-14 05:58:45 -04:00
|
|
|
// FilenameHasPostProcessPrefix is a set of filenames in /public that
|
|
|
|
// contains a post-processing prefix.
|
|
|
|
FilenameHasPostProcessPrefix []string
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
templateProvider ResourceProvider
|
2019-12-10 13:56:44 -05:00
|
|
|
WithTemplate func(templ tpl.TemplateManager) error `json:"-"`
|
|
|
|
|
|
|
|
// Used in tests
|
2022-03-17 17:03:27 -04:00
|
|
|
OverloadedTemplateFuncs map[string]any
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
translationProvider ResourceProvider
|
2017-09-26 14:03:04 -04:00
|
|
|
|
|
|
|
Metrics metrics.Provider
|
2018-04-19 12:06:40 -04:00
|
|
|
|
|
|
|
// Timeout is configurable in site config.
|
|
|
|
Timeout time.Duration
|
2018-07-11 13:23:22 -04:00
|
|
|
|
|
|
|
// BuildStartListeners will be notified before a build starts.
|
|
|
|
BuildStartListeners *Listeners
|
2018-10-21 06:20:21 -04:00
|
|
|
|
2020-12-23 03:26:23 -05:00
|
|
|
// Resources that gets closed when the build is done or the server shuts down.
|
|
|
|
BuildClosers *Closers
|
|
|
|
|
2020-02-25 15:40:02 -05:00
|
|
|
// Atomic values set during a build.
|
|
|
|
// This is common/global for all sites.
|
|
|
|
BuildState *BuildState
|
2020-01-15 09:59:56 -05:00
|
|
|
|
2020-09-07 09:07:10 -04:00
|
|
|
// Whether we are in running (server) mode
|
|
|
|
Running bool
|
|
|
|
|
2018-10-21 06:20:21 -04:00
|
|
|
*globalErrHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
type globalErrHandler struct {
|
|
|
|
// Channel for some "hard to get to" build errors
|
|
|
|
buildErrors chan error
|
|
|
|
}
|
|
|
|
|
|
|
|
// SendErr sends the error on a channel to be handled later.
|
|
|
|
// This can be used in situations where returning and aborting the current
|
|
|
|
// operation isn't practical.
|
|
|
|
func (e *globalErrHandler) SendError(err error) {
|
|
|
|
if e.buildErrors != nil {
|
|
|
|
select {
|
|
|
|
case e.buildErrors <- err:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
jww.ERROR.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *globalErrHandler) StartErrorCollector() chan error {
|
|
|
|
e.buildErrors = make(chan error, 10)
|
|
|
|
return e.buildErrors
|
2018-07-11 13:23:22 -04:00
|
|
|
}
|
|
|
|
|
2018-09-06 14:23:56 -04:00
|
|
|
// Listeners represents an event listener.
|
2018-07-11 13:23:22 -04:00
|
|
|
type Listeners struct {
|
|
|
|
sync.Mutex
|
|
|
|
|
|
|
|
// A list of funcs to be notified about an event.
|
|
|
|
listeners []func()
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:23:56 -04:00
|
|
|
// Add adds a function to a Listeners instance.
|
2018-07-11 13:23:22 -04:00
|
|
|
func (b *Listeners) Add(f func()) {
|
2018-12-21 10:21:13 -05:00
|
|
|
if b == nil {
|
|
|
|
return
|
|
|
|
}
|
2018-07-11 13:23:22 -04:00
|
|
|
b.Lock()
|
|
|
|
defer b.Unlock()
|
|
|
|
b.listeners = append(b.listeners, f)
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:23:56 -04:00
|
|
|
// Notify executes all listener functions.
|
2018-07-11 13:23:22 -04:00
|
|
|
func (b *Listeners) Notify() {
|
|
|
|
b.Lock()
|
|
|
|
defer b.Unlock()
|
|
|
|
for _, notify := range b.listeners {
|
|
|
|
notify()
|
|
|
|
}
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
2017-03-09 08:18:12 -05:00
|
|
|
// ResourceProvider is used to create and refresh, and clone resources needed.
|
2017-02-04 22:20:06 -05:00
|
|
|
type ResourceProvider interface {
|
2017-01-10 04:55:03 -05:00
|
|
|
Update(deps *Deps) error
|
|
|
|
Clone(deps *Deps) error
|
|
|
|
}
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
func (d *Deps) Tmpl() tpl.TemplateHandler {
|
|
|
|
return d.tmpl
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Deps) TextTmpl() tpl.TemplateParseFinder {
|
|
|
|
return d.textTmpl
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Deps) SetTmpl(tmpl tpl.TemplateHandler) {
|
|
|
|
d.tmpl = tmpl
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Deps) SetTextTmpl(tmpl tpl.TemplateParseFinder) {
|
|
|
|
d.textTmpl = tmpl
|
2017-04-30 15:52:56 -04:00
|
|
|
}
|
|
|
|
|
2017-08-02 08:25:05 -04:00
|
|
|
// LoadResources loads translations and templates.
|
2017-02-04 22:20:06 -05:00
|
|
|
func (d *Deps) LoadResources() error {
|
|
|
|
// Note that the translations need to be loaded before the templates.
|
|
|
|
if err := d.translationProvider.Update(d); err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return fmt.Errorf("loading translations: %w", err)
|
2017-02-04 22:20:06 -05:00
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
if err := d.templateProvider.Update(d); err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return fmt.Errorf("loading templates: %w", err)
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
2017-04-30 15:52:56 -04:00
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-08-02 08:25:05 -04:00
|
|
|
// New initializes a Dep struct.
|
|
|
|
// Defaults are set for nil values,
|
|
|
|
// but TemplateProvider, TranslationProvider and Language are always required.
|
2017-03-25 09:37:04 -04:00
|
|
|
func New(cfg DepsCfg) (*Deps, error) {
|
2017-01-10 04:55:03 -05:00
|
|
|
var (
|
|
|
|
logger = cfg.Logger
|
|
|
|
fs = cfg.Fs
|
2022-09-14 05:58:45 -04:00
|
|
|
d *Deps
|
2017-01-10 04:55:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
if cfg.TemplateProvider == nil {
|
|
|
|
panic("Must have a TemplateProvider")
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
if cfg.TranslationProvider == nil {
|
|
|
|
panic("Must have a TranslationProvider")
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
if cfg.Language == nil {
|
|
|
|
panic("Must have a Language")
|
|
|
|
}
|
|
|
|
|
|
|
|
if logger == nil {
|
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
|
|
|
logger = loggers.NewErrorLogger()
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if fs == nil {
|
2017-02-04 22:20:06 -05:00
|
|
|
// Default to the production file system.
|
|
|
|
fs = hugofs.NewDefault(cfg.Language)
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
2018-12-21 10:21:13 -05:00
|
|
|
if cfg.MediaTypes == nil {
|
|
|
|
cfg.MediaTypes = media.DefaultTypes
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.OutputFormats == nil {
|
|
|
|
cfg.OutputFormats = output.DefaultFormats
|
|
|
|
}
|
|
|
|
|
2021-12-12 06:11:11 -05:00
|
|
|
securityConfig, err := security.DecodeConfig(cfg.Cfg)
|
|
|
|
if err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return nil, fmt.Errorf("failed to create security config from configuration: %w", err)
|
2021-12-12 06:11:11 -05:00
|
|
|
}
|
|
|
|
execHelper := hexec.New(securityConfig)
|
|
|
|
|
2022-09-14 05:58:45 -04:00
|
|
|
var filenameHasPostProcessPrefixMu sync.Mutex
|
2022-09-26 11:34:20 -04:00
|
|
|
hashBytesReceiverFunc := func(name string, match bool) {
|
2022-09-14 05:58:45 -04:00
|
|
|
if !match {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
filenameHasPostProcessPrefixMu.Lock()
|
|
|
|
d.FilenameHasPostProcessPrefix = append(d.FilenameHasPostProcessPrefix, name)
|
|
|
|
filenameHasPostProcessPrefixMu.Unlock()
|
2022-09-26 11:34:20 -04:00
|
|
|
}
|
2022-09-14 05:58:45 -04:00
|
|
|
|
2022-09-26 11:34:20 -04:00
|
|
|
// Skip binary files.
|
|
|
|
hashBytesSHouldCheck := func(name string) bool {
|
|
|
|
ext := strings.TrimPrefix(filepath.Ext(name), ".")
|
|
|
|
mime, _, found := cfg.MediaTypes.GetBySuffix(ext)
|
|
|
|
if !found {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch mime.MainType {
|
|
|
|
case "text", "application":
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2022-09-14 05:58:45 -04:00
|
|
|
}
|
2022-09-26 11:34:20 -04:00
|
|
|
fs.PublishDir = hugofs.NewHasBytesReceiver(fs.PublishDir, hashBytesSHouldCheck, hashBytesReceiverFunc, []byte(postpub.PostProcessPrefix))
|
2022-09-14 05:58:45 -04:00
|
|
|
|
2019-07-24 18:12:40 -04:00
|
|
|
ps, err := helpers.NewPathSpec(fs, cfg.Language, logger)
|
2017-03-25 09:37:04 -04:00
|
|
|
if err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return nil, fmt.Errorf("create PathSpec: %w", err)
|
2017-03-25 09:37:04 -04:00
|
|
|
}
|
|
|
|
|
2018-11-23 03:16:42 -05:00
|
|
|
fileCaches, err := filecache.NewCaches(ps)
|
2018-11-08 04:24:13 -05:00
|
|
|
if err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return nil, fmt.Errorf("failed to create file caches from configuration: %w", err)
|
2018-11-08 04:24:13 -05:00
|
|
|
}
|
|
|
|
|
2020-03-10 13:12:11 -04:00
|
|
|
errorHandler := &globalErrHandler{}
|
2020-02-25 15:40:02 -05:00
|
|
|
buildState := &BuildState{}
|
2020-03-10 13:12:11 -04:00
|
|
|
|
2021-12-12 06:11:11 -05:00
|
|
|
resourceSpec, err := resources.NewSpec(ps, fileCaches, buildState, logger, errorHandler, execHelper, cfg.OutputFormats, cfg.MediaTypes)
|
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
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-12 06:11:11 -05:00
|
|
|
contentSpec, err := helpers.NewContentSpec(cfg.Language, logger, ps.BaseFs.Content.Fs, execHelper)
|
2017-09-25 02:59:02 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
sp := source.NewSourceSpec(ps, nil, fs.Source)
|
: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
|
|
|
|
2023-01-24 14:57:15 -05:00
|
|
|
timeout := 30 * time.Second
|
|
|
|
if cfg.Cfg.IsSet("timeout") {
|
|
|
|
v := cfg.Cfg.Get("timeout")
|
|
|
|
d, err := types.ToDurationE(v)
|
|
|
|
if err == nil {
|
|
|
|
timeout = d
|
|
|
|
}
|
2018-04-19 12:06:40 -04:00
|
|
|
}
|
2020-10-21 05:17:48 -04:00
|
|
|
ignoreErrors := cast.ToStringSlice(cfg.Cfg.Get("ignoreErrors"))
|
|
|
|
ignorableLogger := loggers.NewIgnorableLogger(logger, ignoreErrors...)
|
|
|
|
|
2021-06-07 10:36:48 -04:00
|
|
|
logDistinct := helpers.NewDistinctLogger(logger)
|
2018-05-23 04:03:11 -04:00
|
|
|
|
2022-09-14 05:58:45 -04:00
|
|
|
d = &Deps{
|
2019-12-10 13:56:44 -05:00
|
|
|
Fs: fs,
|
2020-10-21 05:17:48 -04:00
|
|
|
Log: ignorableLogger,
|
2021-06-07 10:36:48 -04:00
|
|
|
LogDistinct: logDistinct,
|
2021-12-12 06:11:11 -05:00
|
|
|
ExecHelper: execHelper,
|
2019-12-10 13:56:44 -05:00
|
|
|
templateProvider: cfg.TemplateProvider,
|
|
|
|
translationProvider: cfg.TranslationProvider,
|
|
|
|
WithTemplate: cfg.WithTemplate,
|
|
|
|
OverloadedTemplateFuncs: cfg.OverloadedTemplateFuncs,
|
|
|
|
PathSpec: ps,
|
|
|
|
ContentSpec: contentSpec,
|
|
|
|
SourceSpec: sp,
|
|
|
|
ResourceSpec: resourceSpec,
|
|
|
|
Cfg: cfg.Language,
|
|
|
|
Language: cfg.Language,
|
|
|
|
Site: cfg.Site,
|
|
|
|
FileCaches: fileCaches,
|
|
|
|
BuildStartListeners: &Listeners{},
|
2020-12-23 03:26:23 -05:00
|
|
|
BuildClosers: &Closers{},
|
2020-02-25 15:40:02 -05:00
|
|
|
BuildState: buildState,
|
2020-09-07 09:07:10 -04:00
|
|
|
Running: cfg.Running,
|
2023-01-24 14:57:15 -05:00
|
|
|
Timeout: timeout,
|
2020-03-10 13:12:11 -04:00
|
|
|
globalErrHandler: errorHandler,
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
2017-09-26 14:03:04 -04:00
|
|
|
if cfg.Cfg.GetBool("templateMetrics") {
|
2017-10-04 16:12:51 -04:00
|
|
|
d.Metrics = metrics.NewProvider(cfg.Cfg.GetBool("templateMetricsHints"))
|
2017-09-26 14:03:04 -04:00
|
|
|
}
|
|
|
|
|
2017-03-25 09:37:04 -04:00
|
|
|
return d, nil
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
2020-12-23 03:26:23 -05:00
|
|
|
func (d *Deps) Close() error {
|
|
|
|
return d.BuildClosers.Close()
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// ForLanguage creates a copy of the Deps with the language dependent
|
|
|
|
// parts switched out.
|
2018-11-26 04:11:22 -05:00
|
|
|
func (d Deps) ForLanguage(cfg DepsCfg, onCreated func(d *Deps) error) (*Deps, error) {
|
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
|
|
|
l := cfg.Language
|
2017-03-25 09:37:04 -04:00
|
|
|
var err error
|
|
|
|
|
2019-07-24 18:12:40 -04:00
|
|
|
d.PathSpec, err = helpers.NewPathSpecWithBaseBaseFsProvided(d.Fs, l, d.Log, d.BaseFs)
|
2017-03-25 09:37:04 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2021-12-12 06:11:11 -05:00
|
|
|
d.ContentSpec, err = helpers.NewContentSpec(l, d.Log, d.BaseFs.Content.Fs, d.ExecHelper)
|
2017-09-25 02:59:02 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
d.Site = cfg.Site
|
|
|
|
|
2020-10-05 07:34:14 -04:00
|
|
|
// These are common for all sites, so reuse.
|
2018-07-31 14:04:36 -04:00
|
|
|
// TODO(bep) clean up these inits.
|
|
|
|
resourceCache := d.ResourceSpec.ResourceCache
|
2020-10-05 07:34:14 -04:00
|
|
|
postBuildAssets := d.ResourceSpec.PostBuildAssets
|
2021-12-12 06:11:11 -05:00
|
|
|
d.ResourceSpec, err = resources.NewSpec(d.PathSpec, d.ResourceSpec.FileCaches, d.BuildState, d.Log, d.globalErrHandler, d.ExecHelper, cfg.OutputFormats, cfg.MediaTypes)
|
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
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-07-31 14:04:36 -04:00
|
|
|
d.ResourceSpec.ResourceCache = resourceCache
|
2020-10-05 07:34:14 -04:00
|
|
|
d.ResourceSpec.PostBuildAssets = postBuildAssets
|
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
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
d.Cfg = l
|
|
|
|
d.Language = l
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
if onCreated != nil {
|
|
|
|
if err = onCreated(&d); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
if err := d.translationProvider.Clone(&d); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
if err := d.templateProvider.Clone(&d); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:23:22 -04:00
|
|
|
d.BuildStartListeners = &Listeners{}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
return &d, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DepsCfg contains configuration options that can be used to configure Hugo
|
|
|
|
// on a global level, i.e. logging etc.
|
|
|
|
// Nil values will be given default values.
|
|
|
|
type DepsCfg struct {
|
|
|
|
|
|
|
|
// The Logger to use.
|
2020-10-21 05:17:48 -04:00
|
|
|
Logger loggers.Logger
|
2017-01-10 04:55:03 -05:00
|
|
|
|
|
|
|
// The file systems to use
|
|
|
|
Fs *hugofs.Fs
|
|
|
|
|
|
|
|
// The language to use.
|
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
|
|
|
Language *langs.Language
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
// The Site in use
|
2019-01-02 06:33:26 -05:00
|
|
|
Site page.Site
|
2018-11-26 04:11:22 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// The configuration to use.
|
|
|
|
Cfg config.Provider
|
|
|
|
|
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
|
|
|
// The media types configured.
|
|
|
|
MediaTypes media.Types
|
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
// The output formats configured.
|
|
|
|
OutputFormats output.Formats
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// Template handling.
|
2017-02-04 22:20:06 -05:00
|
|
|
TemplateProvider ResourceProvider
|
2019-12-10 13:56:44 -05:00
|
|
|
WithTemplate func(templ tpl.TemplateManager) error
|
|
|
|
// Used in tests
|
2022-03-17 17:03:27 -04:00
|
|
|
OverloadedTemplateFuncs map[string]any
|
2017-02-04 22:20:06 -05:00
|
|
|
|
|
|
|
// i18n handling.
|
|
|
|
TranslationProvider ResourceProvider
|
: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
|
|
|
|
|
|
|
// Whether we are in running (server) mode
|
|
|
|
Running bool
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
2020-01-15 09:59:56 -05:00
|
|
|
|
2020-02-25 15:40:02 -05:00
|
|
|
// BuildState are flags that may be turned on during a build.
|
|
|
|
type BuildState struct {
|
|
|
|
counter uint64
|
2020-01-15 09:59:56 -05:00
|
|
|
}
|
|
|
|
|
2020-02-25 15:40:02 -05:00
|
|
|
func (b *BuildState) Incr() int {
|
|
|
|
return int(atomic.AddUint64(&b.counter, uint64(1)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewBuildState() BuildState {
|
|
|
|
return BuildState{}
|
2020-01-15 09:59:56 -05:00
|
|
|
}
|
2020-12-23 03:26:23 -05:00
|
|
|
|
|
|
|
type Closer interface {
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Closers struct {
|
|
|
|
mu sync.Mutex
|
|
|
|
cs []Closer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cs *Closers) Add(c Closer) {
|
|
|
|
cs.mu.Lock()
|
|
|
|
defer cs.mu.Unlock()
|
|
|
|
cs.cs = append(cs.cs, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cs *Closers) Close() error {
|
|
|
|
cs.mu.Lock()
|
|
|
|
defer cs.mu.Unlock()
|
|
|
|
for _, c := range cs.cs {
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
cs.cs = cs.cs[:0]
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|