2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2013-07-04 11:32:55 -04:00
|
|
|
//
|
2015-11-23 22:16:36 -05:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
2013-07-04 11:32:55 -04:00
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-11-23 22:16:36 -05:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-04 11:32:55 -04:00
|
|
|
//
|
|
|
|
// 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 hugolib
|
|
|
|
|
|
|
|
import (
|
2014-01-29 17:50:31 -05:00
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"io"
|
2018-07-18 13:58:39 -04:00
|
|
|
"log"
|
2017-04-04 12:05:19 -04:00
|
|
|
"mime"
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
"net/url"
|
2019-01-02 06:33:26 -05:00
|
|
|
"path"
|
2014-12-27 08:11:19 -05:00
|
|
|
"path/filepath"
|
2020-09-20 07:34:45 -04:00
|
|
|
"regexp"
|
2022-01-08 05:35:30 -05:00
|
|
|
"runtime"
|
2017-04-28 03:40:50 -04:00
|
|
|
"sort"
|
2014-08-29 13:40:21 -04:00
|
|
|
"strconv"
|
2014-01-29 17:50:31 -05:00
|
|
|
"strings"
|
|
|
|
"time"
|
2014-03-31 13:23:34 -04:00
|
|
|
|
2022-12-14 06:20:13 -05:00
|
|
|
"github.com/gohugoio/hugo/common/herrors"
|
2022-04-26 13:57:04 -04:00
|
|
|
"github.com/gohugoio/hugo/common/htime"
|
2022-02-17 07:04:00 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hugio"
|
2021-07-05 04:13:41 -04:00
|
|
|
"github.com/gohugoio/hugo/common/types"
|
2022-01-11 09:07:04 -05:00
|
|
|
"github.com/gohugoio/hugo/modules"
|
2022-01-08 05:35:30 -05:00
|
|
|
"golang.org/x/text/unicode/norm"
|
2021-07-05 04:13:41 -04:00
|
|
|
|
2021-06-18 04:27:27 -04:00
|
|
|
"github.com/gohugoio/hugo/common/paths"
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
"github.com/gohugoio/hugo/common/constants"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/common/loggers"
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
"github.com/gohugoio/hugo/resources"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/identity"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/markup/converter/hooks"
|
|
|
|
|
2019-11-21 15:59:38 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/resource"
|
|
|
|
|
2019-08-16 09:55:03 -04:00
|
|
|
"github.com/gohugoio/hugo/markup/converter"
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"github.com/gohugoio/hugo/hugofs/files"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/common/maps"
|
|
|
|
|
2018-11-01 06:28:30 -04:00
|
|
|
"github.com/gohugoio/hugo/common/text"
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hugo"
|
2018-08-05 05:13:49 -04:00
|
|
|
"github.com/gohugoio/hugo/publisher"
|
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
|
|
|
|
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"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
: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-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/lazy"
|
2017-04-04 03:12:33 -04:00
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/media"
|
2015-01-30 14:51:06 -05:00
|
|
|
|
2016-04-20 10:28:26 -04:00
|
|
|
"github.com/fsnotify/fsnotify"
|
2017-06-13 12:42:45 -04:00
|
|
|
bp "github.com/gohugoio/hugo/bufferpool"
|
|
|
|
"github.com/gohugoio/hugo/deps"
|
|
|
|
"github.com/gohugoio/hugo/helpers"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/navigation"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/output"
|
2017-08-19 07:16:00 -04:00
|
|
|
"github.com/gohugoio/hugo/related"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page/pagemeta"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/source"
|
|
|
|
"github.com/gohugoio/hugo/tpl"
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2017-06-13 13:07:35 -04:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/cast"
|
2013-07-04 11:32:55 -04:00
|
|
|
)
|
|
|
|
|
2013-10-17 23:57:25 -04:00
|
|
|
// Site contains all the information relevant for constructing a static
|
2013-09-01 00:13:04 -04:00
|
|
|
// site. The basic flow of information is as follows:
|
|
|
|
//
|
|
|
|
// 1. A list of Files is parsed and then converted into Pages.
|
|
|
|
//
|
2022-12-14 06:20:13 -05:00
|
|
|
// 2. Pages contain sections (based on the file they were generated from),
|
|
|
|
// aliases and slugs (included in a pages frontmatter) which are the
|
|
|
|
// various targets that will get generated. There will be canonical
|
|
|
|
// listing. The canonical path can be overruled based on a pattern.
|
2013-09-01 00:13:04 -04:00
|
|
|
//
|
2022-12-14 06:20:13 -05:00
|
|
|
// 3. Taxonomies are created via configuration and will present some aspect of
|
|
|
|
// the final page and typically a perm url.
|
2013-09-01 00:13:04 -04:00
|
|
|
//
|
2022-12-14 06:20:13 -05:00
|
|
|
// 4. All Pages are passed through a template based on their desired
|
|
|
|
// layout based on numerous different elements.
|
2013-09-01 00:13:04 -04:00
|
|
|
//
|
|
|
|
// 5. The entire collection of files is written to disk.
|
2013-07-04 11:32:55 -04:00
|
|
|
type Site struct {
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
// The owning container. When multiple languages, there will be multiple
|
2021-07-09 05:52:03 -04:00
|
|
|
// sites .
|
2019-01-02 06:33:26 -05:00
|
|
|
h *HugoSites
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2016-11-03 19:34:25 -04:00
|
|
|
*PageCollections
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
taxonomies TaxonomyList
|
2016-10-31 14:53:33 -04:00
|
|
|
|
2017-03-03 04:47:43 -05:00
|
|
|
Sections Taxonomy
|
2019-09-10 05:26:34 -04:00
|
|
|
Info *SiteInfo
|
2017-03-03 04:47:43 -05:00
|
|
|
|
2021-07-09 05:52:03 -04:00
|
|
|
language *langs.Language
|
|
|
|
siteBucket *pagesMapBucket
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
siteCfg siteConfigHolder
|
2017-01-03 11:28:51 -05:00
|
|
|
|
2017-02-18 04:02:12 -05:00
|
|
|
disabledKinds map[string]bool
|
|
|
|
|
2017-03-22 06:34:17 -04:00
|
|
|
// Output formats defined in site config per Page Kind, or some defaults
|
|
|
|
// if not set.
|
|
|
|
// Output formats defined in Page front matter will override these.
|
|
|
|
outputFormats map[string]output.Formats
|
2017-03-09 13:19:29 -05:00
|
|
|
|
2017-04-04 03:12:33 -04:00
|
|
|
// All the output formats and media types available for this site.
|
|
|
|
// These values will be merged from the Hugo defaults, the site config and,
|
|
|
|
// finally, the language settings.
|
|
|
|
outputFormatsConfig output.Formats
|
|
|
|
mediaTypesConfig media.Types
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
siteConfigConfig SiteConfig
|
2018-07-18 13:58:39 -04:00
|
|
|
|
hugolib: Extract date and slug from filename
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter.
This should make it easier to move content from Jekyll to Hugo.
To enable, put this in your `config.toml`:
```toml
[frontmatter]
date = [":filename", ":default"]
```
This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc.
So, if you want to use the `file modification time`, this can be a good configuration:
```toml
[frontmatter]
date = [ "date",":fileModTime", ":default"]
lastmod = ["lastmod" ,":fileModTime", ":default"]
```
The current `:default` values for the different dates are
```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```
The above will now be the same as:
```toml
[frontmatter]
date = [":default"]
lastmod = [":default"]
publishDate = [":default"]
expiryDate = [":default"]
```
Note:
* We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate.
* If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved.
* All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`).
* The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values.
* The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list.
Fixes #285
Closes #3310
Closes #3762
Closes #4340
2018-03-11 06:32:55 -04:00
|
|
|
// How to handle page front matter.
|
|
|
|
frontmatterHandler pagemeta.FrontMatterHandler
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
// We render each site for all the relevant output formats in serial with
|
|
|
|
// this rendering context pointing to the current one.
|
|
|
|
rc *siteRenderingContext
|
|
|
|
|
|
|
|
// The output formats that we need to render this site in. This slice
|
|
|
|
// will be fixed once set.
|
|
|
|
// This will be the union of Site.Pages' outputFormats.
|
|
|
|
// This slice will be sorted.
|
|
|
|
renderFormats output.Formats
|
|
|
|
|
2017-01-03 11:28:51 -05:00
|
|
|
// Logger etc.
|
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
|
|
|
*deps.Deps `json:"-"`
|
2017-03-24 04:19:51 -04:00
|
|
|
|
2017-07-30 11:46:04 -04:00
|
|
|
// The func used to title case titles.
|
|
|
|
titleFunc func(s string) string
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
relatedDocsHandler *page.RelatedDocsHandler
|
2018-07-18 13:58:39 -04:00
|
|
|
siteRefLinker
|
2018-08-05 05:13:49 -04:00
|
|
|
|
|
|
|
publisher publisher.Publisher
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
menus navigation.Menus
|
|
|
|
|
|
|
|
// Shortcut to the home page. Note that this may be nil if
|
|
|
|
// home page, for some odd reason, is disabled.
|
|
|
|
home *pageState
|
|
|
|
|
|
|
|
// The last modification date of this site.
|
|
|
|
lastmod time.Time
|
|
|
|
|
|
|
|
// Lazily loaded site dependencies
|
|
|
|
init *siteInit
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
func (s *Site) Taxonomies() TaxonomyList {
|
|
|
|
s.init.taxonomies.Do()
|
|
|
|
return s.taxonomies
|
|
|
|
}
|
|
|
|
|
|
|
|
type taxonomiesConfig map[string]string
|
|
|
|
|
|
|
|
func (t taxonomiesConfig) Values() []viewName {
|
|
|
|
var vals []viewName
|
|
|
|
for k, v := range t {
|
|
|
|
vals = append(vals, viewName{singular: k, plural: v})
|
|
|
|
}
|
|
|
|
sort.Slice(vals, func(i, j int) bool {
|
|
|
|
return vals[i].plural < vals[j].plural
|
|
|
|
})
|
|
|
|
|
|
|
|
return vals
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
type siteConfigHolder struct {
|
|
|
|
sitemap config.Sitemap
|
2019-09-10 05:26:34 -04:00
|
|
|
taxonomiesConfig taxonomiesConfig
|
2019-01-02 06:33:26 -05:00
|
|
|
timeout time.Duration
|
|
|
|
hasCJKLanguage bool
|
|
|
|
enableEmoji bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lazily loaded site dependencies.
|
|
|
|
type siteInit struct {
|
|
|
|
prevNext *lazy.Init
|
|
|
|
prevNextInSection *lazy.Init
|
|
|
|
menus *lazy.Init
|
2019-09-10 05:26:34 -04:00
|
|
|
taxonomies *lazy.Init
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (init *siteInit) Reset() {
|
|
|
|
init.prevNext.Reset()
|
|
|
|
init.prevNextInSection.Reset()
|
|
|
|
init.menus.Reset()
|
2019-09-10 05:26:34 -04:00
|
|
|
init.taxonomies.Reset()
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
2019-11-25 06:49:04 -05:00
|
|
|
func (s *Site) initInit(init *lazy.Init, pctx pageContext) bool {
|
2019-01-02 06:33:26 -05:00
|
|
|
_, err := init.Do()
|
|
|
|
if err != nil {
|
|
|
|
s.h.FatalError(pctx.wrapError(err))
|
|
|
|
}
|
2019-11-25 06:49:04 -05:00
|
|
|
return err == nil
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) prepareInits() {
|
|
|
|
s.init = &siteInit{}
|
|
|
|
|
|
|
|
var init lazy.Init
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
s.init.prevNext = init.Branch(func() (any, error) {
|
2019-09-10 05:26:34 -04:00
|
|
|
regularPages := s.RegularPages()
|
2019-01-02 06:33:26 -05:00
|
|
|
for i, p := range regularPages {
|
2019-09-10 05:26:34 -04:00
|
|
|
np, ok := p.(nextPrevProvider)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
pos := np.getNextPrev()
|
|
|
|
if pos == nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
continue
|
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
|
|
|
|
pos.nextPage = nil
|
|
|
|
pos.prevPage = nil
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
if i > 0 {
|
2019-09-10 05:26:34 -04:00
|
|
|
pos.nextPage = regularPages[i-1]
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if i < len(regularPages)-1 {
|
2019-09-10 05:26:34 -04:00
|
|
|
pos.prevPage = regularPages[i+1]
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
s.init.prevNextInSection = init.Branch(func() (any, error) {
|
2019-09-10 05:26:34 -04:00
|
|
|
var sections page.Pages
|
2020-03-20 04:37:21 -04:00
|
|
|
s.home.treeRef.m.collectSectionsRecursiveIncludingSelf(pageMapQuery{Prefix: s.home.treeRef.key}, func(n *contentNode) {
|
2019-09-10 05:26:34 -04:00
|
|
|
sections = append(sections, n.p)
|
|
|
|
})
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
setNextPrev := func(pas page.Pages) {
|
|
|
|
for i, p := range pas {
|
|
|
|
np, ok := p.(nextPrevInSectionProvider)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
pos := np.getNextPrevInSection()
|
|
|
|
if pos == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.nextPage = nil
|
|
|
|
pos.prevPage = nil
|
|
|
|
|
|
|
|
if i > 0 {
|
|
|
|
pos.nextPage = pas[i-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if i < len(pas)-1 {
|
|
|
|
pos.prevPage = pas[i+1]
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
for _, sect := range sections {
|
|
|
|
treeRef := sect.(treeRefProvider).getTreeRef()
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
var pas page.Pages
|
2020-03-20 04:37:21 -04:00
|
|
|
treeRef.m.collectPages(pageMapQuery{Prefix: treeRef.key + cmBranchSeparator}, func(c *contentNode) {
|
2019-09-10 05:26:34 -04:00
|
|
|
pas = append(pas, c.p)
|
|
|
|
})
|
|
|
|
page.SortByDefault(pas)
|
|
|
|
|
|
|
|
setNextPrev(pas)
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
// The root section only goes one level down.
|
|
|
|
treeRef := s.home.getTreeRef()
|
|
|
|
|
|
|
|
var pas page.Pages
|
2020-03-20 04:37:21 -04:00
|
|
|
treeRef.m.collectPages(pageMapQuery{Prefix: treeRef.key + cmBranchSeparator}, func(c *contentNode) {
|
2019-09-10 05:26:34 -04:00
|
|
|
pas = append(pas, c.p)
|
|
|
|
})
|
|
|
|
page.SortByDefault(pas)
|
|
|
|
|
|
|
|
setNextPrev(pas)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
s.init.menus = init.Branch(func() (any, error) {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.assembleMenus()
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
s.init.taxonomies = init.Branch(func() (any, error) {
|
2019-09-10 05:26:34 -04:00
|
|
|
err := s.pageMap.assembleTaxonomies()
|
|
|
|
return nil, err
|
|
|
|
})
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
type siteRenderingContext struct {
|
|
|
|
output.Format
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) Menus() navigation.Menus {
|
|
|
|
s.init.menus.Do()
|
|
|
|
return s.menus
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
func (s *Site) initRenderFormats() {
|
|
|
|
formatSet := make(map[string]bool)
|
|
|
|
formats := output.Formats{}
|
2019-09-10 05:26:34 -04:00
|
|
|
s.pageMap.pageTrees.WalkRenderable(func(s string, n *contentNode) bool {
|
|
|
|
for _, f := range n.p.m.configuredOutputFormats {
|
2017-04-28 03:40:50 -04:00
|
|
|
if !formatSet[f.Name] {
|
|
|
|
formats = append(formats, f)
|
|
|
|
formatSet[f.Name] = true
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
return false
|
|
|
|
})
|
2017-04-28 03:40:50 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Add the per kind configured output formats
|
|
|
|
for _, kind := range allKindsInPages {
|
|
|
|
if siteFormats, found := s.outputFormats[kind]; found {
|
|
|
|
for _, f := range siteFormats {
|
|
|
|
if !formatSet[f.Name] {
|
|
|
|
formats = append(formats, f)
|
|
|
|
formatSet[f.Name] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
sort.Sort(formats)
|
|
|
|
s.renderFormats = formats
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) GetRelatedDocsHandler() *page.RelatedDocsHandler {
|
|
|
|
return s.relatedDocsHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) Language() *langs.Language {
|
|
|
|
return s.language
|
|
|
|
}
|
|
|
|
|
2017-02-18 04:02:12 -05:00
|
|
|
func (s *Site) isEnabled(kind string) bool {
|
|
|
|
if kind == kindUnknown {
|
|
|
|
panic("Unknown kind")
|
|
|
|
}
|
|
|
|
return !s.disabledKinds[kind]
|
|
|
|
}
|
|
|
|
|
2016-08-07 18:12:06 -04:00
|
|
|
// reset returns a new Site prepared for rebuild.
|
|
|
|
func (s *Site) reset() *Site {
|
2020-12-02 07:23:25 -05:00
|
|
|
return &Site{
|
2021-12-12 06:11:11 -05:00
|
|
|
Deps: s.Deps,
|
|
|
|
disabledKinds: s.disabledKinds,
|
|
|
|
titleFunc: s.titleFunc,
|
|
|
|
relatedDocsHandler: s.relatedDocsHandler.Clone(),
|
|
|
|
siteRefLinker: s.siteRefLinker,
|
|
|
|
outputFormats: s.outputFormats,
|
|
|
|
rc: s.rc,
|
|
|
|
outputFormatsConfig: s.outputFormatsConfig,
|
|
|
|
frontmatterHandler: s.frontmatterHandler,
|
|
|
|
mediaTypesConfig: s.mediaTypesConfig,
|
|
|
|
language: s.language,
|
|
|
|
siteBucket: s.siteBucket,
|
|
|
|
h: s.h,
|
|
|
|
publisher: s.publisher,
|
|
|
|
siteConfigConfig: s.siteConfigConfig,
|
|
|
|
init: s.init,
|
|
|
|
PageCollections: s.PageCollections,
|
|
|
|
siteCfg: s.siteCfg,
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2016-07-26 04:24:27 -04:00
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// newSite creates a new site with the given configuration.
|
|
|
|
func newSite(cfg deps.DepsCfg) (*Site, error) {
|
|
|
|
if cfg.Language == nil {
|
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
|
|
|
cfg.Language = langs.NewDefaultLanguage(cfg.Cfg)
|
2017-01-09 19:36:59 -05:00
|
|
|
}
|
2020-06-16 09:43:50 -04:00
|
|
|
if cfg.Logger == nil {
|
|
|
|
panic("logger must be set")
|
|
|
|
}
|
|
|
|
|
|
|
|
ignoreErrors := cast.ToStringSlice(cfg.Language.Get("ignoreErrors"))
|
|
|
|
ignorableLogger := loggers.NewIgnorableLogger(cfg.Logger, ignoreErrors...)
|
2017-01-09 19:36:59 -05:00
|
|
|
|
2017-02-18 04:02:12 -05:00
|
|
|
disabledKinds := make(map[string]bool)
|
|
|
|
for _, disabled := range cast.ToStringSlice(cfg.Language.Get("disableKinds")) {
|
|
|
|
disabledKinds[disabled] = true
|
|
|
|
}
|
|
|
|
|
2020-06-16 09:43:50 -04:00
|
|
|
if disabledKinds["taxonomyTerm"] {
|
|
|
|
// Correct from the value it had before Hugo 0.73.0.
|
|
|
|
if disabledKinds[page.KindTaxonomy] {
|
|
|
|
disabledKinds[page.KindTerm] = true
|
|
|
|
} else {
|
|
|
|
disabledKinds[page.KindTaxonomy] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(disabledKinds, "taxonomyTerm")
|
|
|
|
} else if disabledKinds[page.KindTaxonomy] && !disabledKinds[page.KindTerm] {
|
|
|
|
// This is a potentially ambigous situation. It may be correct.
|
2020-10-21 05:17:48 -04:00
|
|
|
ignorableLogger.Errorsf(constants.ErrIDAmbigousDisableKindTaxonomy, `You have the value 'taxonomy' in the disabledKinds list. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term).
|
2020-06-16 09:43:50 -04:00
|
|
|
But this also means that your site configuration may not do what you expect. If it is correct, you can suppress this message by following the instructions below.`)
|
|
|
|
}
|
|
|
|
|
2017-04-04 03:12:33 -04:00
|
|
|
var (
|
2022-03-17 17:03:27 -04:00
|
|
|
mediaTypesConfig []map[string]any
|
|
|
|
outputFormatsConfig []map[string]any
|
2017-04-04 03:12:33 -04:00
|
|
|
|
|
|
|
siteOutputFormatsConfig output.Formats
|
|
|
|
siteMediaTypesConfig media.Types
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
// Add language last, if set, so it gets precedence.
|
|
|
|
for _, cfg := range []config.Provider{cfg.Cfg, cfg.Language} {
|
|
|
|
if cfg.IsSet("mediaTypes") {
|
|
|
|
mediaTypesConfig = append(mediaTypesConfig, cfg.GetStringMap("mediaTypes"))
|
|
|
|
}
|
|
|
|
if cfg.IsSet("outputFormats") {
|
|
|
|
outputFormatsConfig = append(outputFormatsConfig, cfg.GetStringMap("outputFormats"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
siteMediaTypesConfig, err = media.DecodeTypes(mediaTypesConfig...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
siteOutputFormatsConfig, err = output.DecodeFormats(siteMediaTypesConfig, outputFormatsConfig...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-22 06:34:17 -04:00
|
|
|
|
2020-02-19 02:38:46 -05:00
|
|
|
rssDisabled := disabledKinds[kindRSS]
|
|
|
|
if rssDisabled {
|
2019-09-10 05:26:34 -04:00
|
|
|
// Legacy
|
|
|
|
tmp := siteOutputFormatsConfig[:0]
|
|
|
|
for _, x := range siteOutputFormatsConfig {
|
|
|
|
if !strings.EqualFold(x.Name, "rss") {
|
|
|
|
tmp = append(tmp, x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
siteOutputFormatsConfig = tmp
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
var siteOutputs map[string]any
|
2020-06-16 09:43:50 -04:00
|
|
|
if cfg.Language.IsSet("outputs") {
|
|
|
|
siteOutputs = cfg.Language.GetStringMap("outputs")
|
|
|
|
|
|
|
|
// Check and correct taxonomy kinds vs pre Hugo 0.73.0.
|
|
|
|
v1, hasTaxonomyTerm := siteOutputs["taxonomyterm"]
|
|
|
|
v2, hasTaxonomy := siteOutputs[page.KindTaxonomy]
|
|
|
|
_, hasTerm := siteOutputs[page.KindTerm]
|
|
|
|
if hasTaxonomy && hasTaxonomyTerm {
|
|
|
|
siteOutputs[page.KindTaxonomy] = v1
|
|
|
|
siteOutputs[page.KindTerm] = v2
|
|
|
|
delete(siteOutputs, "taxonomyTerm")
|
|
|
|
} else if hasTaxonomy && !hasTerm {
|
|
|
|
// This is a potentially ambigous situation. It may be correct.
|
2020-10-21 05:17:48 -04:00
|
|
|
ignorableLogger.Errorsf(constants.ErrIDAmbigousOutputKindTaxonomy, `You have configured output formats for 'taxonomy' in your site configuration. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term).
|
2020-06-16 09:43:50 -04:00
|
|
|
But this also means that your site configuration may not do what you expect. If it is correct, you can suppress this message by following the instructions below.`)
|
|
|
|
}
|
|
|
|
if !hasTaxonomy && hasTaxonomyTerm {
|
|
|
|
siteOutputs[page.KindTaxonomy] = v1
|
|
|
|
delete(siteOutputs, "taxonomyterm")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
outputFormats, err := createSiteOutputFormats(siteOutputFormatsConfig, siteOutputs, rssDisabled)
|
2017-03-22 06:34:17 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-09 13:19:29 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
taxonomies := cfg.Language.GetStringMapString("taxonomies")
|
|
|
|
|
2017-08-19 07:16:00 -04:00
|
|
|
var relatedContentConfig related.Config
|
|
|
|
|
|
|
|
if cfg.Language.IsSet("related") {
|
2021-06-09 04:58:18 -04:00
|
|
|
relatedContentConfig, err = related.DecodeConfig(cfg.Language.GetParams("related"))
|
2017-08-19 07:16:00 -04:00
|
|
|
if err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return nil, fmt.Errorf("failed to decode related config: %w", err)
|
2017-08-19 07:16:00 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
relatedContentConfig = related.DefaultConfig
|
|
|
|
if _, found := taxonomies["tag"]; found {
|
|
|
|
relatedContentConfig.Add(related.IndexConfig{Name: "tags", Weight: 80})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-30 11:46:04 -04:00
|
|
|
titleFunc := helpers.GetTitleFunc(cfg.Language.GetString("titleCaseStyle"))
|
|
|
|
|
hugolib: Extract date and slug from filename
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter.
This should make it easier to move content from Jekyll to Hugo.
To enable, put this in your `config.toml`:
```toml
[frontmatter]
date = [":filename", ":default"]
```
This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc.
So, if you want to use the `file modification time`, this can be a good configuration:
```toml
[frontmatter]
date = [ "date",":fileModTime", ":default"]
lastmod = ["lastmod" ,":fileModTime", ":default"]
```
The current `:default` values for the different dates are
```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```
The above will now be the same as:
```toml
[frontmatter]
date = [":default"]
lastmod = [":default"]
publishDate = [":default"]
expiryDate = [":default"]
```
Note:
* We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate.
* If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved.
* All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`).
* The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values.
* The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list.
Fixes #285
Closes #3310
Closes #3762
Closes #4340
2018-03-11 06:32:55 -04:00
|
|
|
frontMatterHandler, err := pagemeta.NewFrontmatterHandler(cfg.Logger, cfg.Cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-11-25 06:49:04 -05:00
|
|
|
timeout := 30 * time.Second
|
|
|
|
if cfg.Language.IsSet("timeout") {
|
2019-11-29 04:50:36 -05:00
|
|
|
v := cfg.Language.Get("timeout")
|
2021-07-05 04:13:41 -04:00
|
|
|
d, err := types.ToDurationE(v)
|
|
|
|
if err == nil {
|
|
|
|
timeout = d
|
2019-11-25 06:49:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
siteConfig := siteConfigHolder{
|
|
|
|
sitemap: config.DecodeSitemap(config.Sitemap{Priority: -1, Filename: "sitemap.xml"}, cfg.Language.GetStringMap("sitemap")),
|
|
|
|
taxonomiesConfig: taxonomies,
|
2019-11-25 06:49:04 -05:00
|
|
|
timeout: timeout,
|
2019-01-02 06:33:26 -05:00
|
|
|
hasCJKLanguage: cfg.Language.GetBool("hasCJKLanguage"),
|
|
|
|
enableEmoji: cfg.Language.Cfg.GetBool("enableEmoji"),
|
|
|
|
}
|
|
|
|
|
2021-07-09 05:52:03 -04:00
|
|
|
var siteBucket *pagesMapBucket
|
|
|
|
if cfg.Language.IsSet("cascade") {
|
|
|
|
var err error
|
|
|
|
cascade, err := page.DecodeCascade(cfg.Language.Get("cascade"))
|
|
|
|
if err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return nil, fmt.Errorf("failed to decode cascade config: %s", err)
|
2021-07-09 05:52:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
siteBucket = &pagesMapBucket{
|
|
|
|
cascade: cascade,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
|
2021-07-09 05:52:03 -04:00
|
|
|
s := &Site{
|
2019-09-10 05:26:34 -04:00
|
|
|
language: cfg.Language,
|
2021-07-09 05:52:03 -04:00
|
|
|
siteBucket: siteBucket,
|
2019-09-10 05:26:34 -04:00
|
|
|
disabledKinds: disabledKinds,
|
|
|
|
|
|
|
|
outputFormats: outputFormats,
|
|
|
|
outputFormatsConfig: siteOutputFormatsConfig,
|
|
|
|
mediaTypesConfig: siteMediaTypesConfig,
|
|
|
|
|
2021-12-12 06:11:11 -05:00
|
|
|
siteCfg: siteConfig,
|
2019-09-10 05:26:34 -04:00
|
|
|
|
|
|
|
titleFunc: titleFunc,
|
|
|
|
|
|
|
|
rc: &siteRenderingContext{output.HTMLFormat},
|
|
|
|
|
|
|
|
frontmatterHandler: frontMatterHandler,
|
|
|
|
relatedDocsHandler: page.NewRelatedDocsHandler(relatedContentConfig),
|
2017-03-09 13:19:29 -05:00
|
|
|
}
|
2016-10-24 07:45:30 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
s.prepareInits()
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
return s, nil
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// NewSite creates a new site with the given dependency configuration.
|
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
|
|
|
func NewSite(cfg deps.DepsCfg) (*Site, error) {
|
|
|
|
s, err := newSite(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-09 04:58:18 -04:00
|
|
|
var l configLoader
|
|
|
|
if err = l.applyDeps(cfg, s); err != nil {
|
2017-01-10 04:55:03 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSiteDefaultLang creates a new site in the default language.
|
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
2018-03-18 06:07:24 -04:00
|
|
|
// TODO(bep) test refactor -- remove
|
2019-12-10 13:56:44 -05:00
|
|
|
func NewSiteDefaultLang(withTemplate ...func(templ tpl.TemplateManager) error) (*Site, error) {
|
2021-06-09 04:58:18 -04:00
|
|
|
l := configLoader{cfg: config.New()}
|
|
|
|
if err := l.applyConfigDefaults(); err != nil {
|
2017-09-25 02:59:02 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-06-09 04:58:18 -04:00
|
|
|
return newSiteForLang(langs.NewDefaultLanguage(l.cfg), withTemplate...)
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
2017-02-15 04:00:34 -05:00
|
|
|
// NewEnglishSite creates a new site in English language.
|
2017-01-10 04:55:03 -05:00
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
2018-03-18 06:07:24 -04:00
|
|
|
// TODO(bep) test refactor -- remove
|
2019-12-10 13:56:44 -05:00
|
|
|
func NewEnglishSite(withTemplate ...func(templ tpl.TemplateManager) error) (*Site, error) {
|
2021-06-09 04:58:18 -04:00
|
|
|
l := configLoader{cfg: config.New()}
|
|
|
|
if err := l.applyConfigDefaults(); err != nil {
|
2017-09-25 02:59:02 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-06-09 04:58:18 -04:00
|
|
|
return newSiteForLang(langs.NewLanguage("en", l.cfg), withTemplate...)
|
2017-02-15 04:00:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// newSiteForLang creates a new site in the given language.
|
2019-12-10 13:56:44 -05:00
|
|
|
func newSiteForLang(lang *langs.Language, withTemplate ...func(templ tpl.TemplateManager) error) (*Site, error) {
|
|
|
|
withTemplates := func(templ tpl.TemplateManager) error {
|
2017-01-10 04:55:03 -05:00
|
|
|
for _, wt := range withTemplate {
|
|
|
|
if err := wt(templ); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
cfg := deps.DepsCfg{WithTemplate: withTemplates, Cfg: lang}
|
2017-02-15 04:00:34 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
return NewSiteForCfg(cfg)
|
2017-02-15 04:00:34 -05:00
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// NewSiteForCfg creates a new site for the given configuration.
|
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
|
|
|
func NewSiteForCfg(cfg deps.DepsCfg) (*Site, error) {
|
2018-07-18 13:58:39 -04:00
|
|
|
h, err := NewHugoSites(cfg)
|
2017-01-10 04:55:03 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-07-18 13:58:39 -04:00
|
|
|
return h.Sites[0], nil
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
type SiteInfo struct {
|
|
|
|
Authors page.AuthorList
|
|
|
|
Social SiteSocial
|
2018-03-15 04:37:30 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
hugoInfo hugo.Info
|
|
|
|
title string
|
|
|
|
RSSLink string
|
2022-03-17 17:03:27 -04:00
|
|
|
Author map[string]any
|
2019-01-02 06:33:26 -05:00
|
|
|
LanguageCode string
|
|
|
|
Copyright string
|
|
|
|
|
|
|
|
permalinks map[string]string
|
|
|
|
|
|
|
|
LanguagePrefix string
|
|
|
|
Languages langs.Languages
|
|
|
|
|
|
|
|
BuildDrafts bool
|
|
|
|
|
|
|
|
canonifyURLs bool
|
|
|
|
relativeURLs bool
|
|
|
|
uglyURLs func(p page.Page) bool
|
2018-03-15 04:37:30 -04:00
|
|
|
|
2016-08-09 14:06:15 -04:00
|
|
|
owner *HugoSites
|
2017-01-10 04:55:03 -05:00
|
|
|
s *Site
|
2018-11-26 04:11:22 -05:00
|
|
|
language *langs.Language
|
2016-08-08 07:55:18 -04:00
|
|
|
defaultContentLanguageInSubdir bool
|
2016-11-23 16:06:15 -05:00
|
|
|
sectionPagesMenu string
|
2014-04-23 02:52:01 -04:00
|
|
|
}
|
2014-04-23 02:55:43 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) Pages() page.Pages {
|
|
|
|
return s.s.Pages()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) RegularPages() page.Pages {
|
|
|
|
return s.s.RegularPages()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) AllPages() page.Pages {
|
|
|
|
return s.s.AllPages()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) AllRegularPages() page.Pages {
|
|
|
|
return s.s.AllRegularPages()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) LastChange() time.Time {
|
|
|
|
return s.s.lastmod
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Title() string {
|
|
|
|
return s.title
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Site() page.Site {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Menus() navigation.Menus {
|
|
|
|
return s.s.Menus()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(bep) type
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *SiteInfo) Taxonomies() any {
|
2019-09-10 05:26:34 -04:00
|
|
|
return s.s.Taxonomies()
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
2019-11-21 15:59:38 -05:00
|
|
|
func (s *SiteInfo) Params() maps.Params {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.s.Language().Params()
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *SiteInfo) Data() map[string]any {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.s.h.Data()
|
|
|
|
}
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
func (s *SiteInfo) Language() *langs.Language {
|
|
|
|
return s.language
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
func (s *SiteInfo) Config() SiteConfig {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.s.siteConfigConfig
|
2018-07-18 13:58:39 -04:00
|
|
|
}
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
func (s *SiteInfo) Hugo() hugo.Info {
|
|
|
|
return s.hugoInfo
|
|
|
|
}
|
|
|
|
|
2018-12-06 04:29:28 -05:00
|
|
|
// Sites is a convenience method to get all the Hugo sites/languages configured.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) Sites() page.Sites {
|
|
|
|
return s.s.h.siteInfos()
|
2018-12-06 04:29:28 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2022-04-05 03:57:58 -04:00
|
|
|
// Current returns the currently rendered Site.
|
2022-04-10 14:30:52 -04:00
|
|
|
// If that isn't set yet, which is the situation before we start rendering,
|
|
|
|
// if will return the Site itself.
|
2022-04-05 03:57:58 -04:00
|
|
|
func (s *SiteInfo) Current() page.Site {
|
2022-04-10 14:30:52 -04:00
|
|
|
if s.s.h.currentSite == nil {
|
|
|
|
return s
|
|
|
|
}
|
2022-04-05 03:57:58 -04:00
|
|
|
return s.s.h.currentSite.Info
|
|
|
|
}
|
|
|
|
|
2016-11-13 08:27:10 -05:00
|
|
|
func (s *SiteInfo) String() string {
|
2019-01-02 06:33:26 -05:00
|
|
|
return fmt.Sprintf("Site(%q)", s.title)
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2017-04-07 12:33:28 -04:00
|
|
|
func (s *SiteInfo) BaseURL() template.URL {
|
|
|
|
return template.URL(s.s.PathSpec.BaseURL.String())
|
|
|
|
}
|
|
|
|
|
2017-11-12 04:03:56 -05:00
|
|
|
// ServerPort returns the port part of the BaseURL, 0 if none found.
|
|
|
|
func (s *SiteInfo) ServerPort() int {
|
|
|
|
ps := s.s.PathSpec.BaseURL.URL().Port()
|
|
|
|
if ps == "" {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
p, err := strconv.Atoi(ps)
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2018-05-22 08:40:06 -04:00
|
|
|
// GoogleAnalytics is kept here for historic reasons.
|
|
|
|
func (s *SiteInfo) GoogleAnalytics() string {
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.Config().Services.GoogleAnalytics.ID
|
2018-05-22 08:40:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// DisqusShortname is kept here for historic reasons.
|
|
|
|
func (s *SiteInfo) DisqusShortname() string {
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.Config().Services.Disqus.Shortname
|
2016-08-07 08:03:03 -04:00
|
|
|
}
|
|
|
|
|
2014-12-09 13:33:55 -05:00
|
|
|
// SiteSocial is a place to put social details on a site level. These are the
|
|
|
|
// standard keys that themes will expect to have available, but can be
|
|
|
|
// expanded to any others on a per site basis
|
|
|
|
// github
|
|
|
|
// facebook
|
|
|
|
// facebook_admin
|
|
|
|
// twitter
|
|
|
|
// twitter_domain
|
|
|
|
// pinterest
|
|
|
|
// instagram
|
|
|
|
// youtube
|
|
|
|
// linkedin
|
|
|
|
type SiteSocial map[string]string
|
|
|
|
|
2017-02-19 17:53:48 -05:00
|
|
|
// Param is a convenience method to do lookups in SiteInfo's Params map.
|
2016-10-17 13:30:21 -04:00
|
|
|
//
|
2019-11-21 15:59:38 -05:00
|
|
|
// This method is also implemented on Page.
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *SiteInfo) Param(key any) (any, error) {
|
2019-11-21 15:59:38 -05:00
|
|
|
return resource.Param(s, nil, key)
|
2016-10-17 13:30:21 -04:00
|
|
|
}
|
|
|
|
|
2016-08-07 08:03:03 -04:00
|
|
|
func (s *SiteInfo) IsMultiLingual() bool {
|
|
|
|
return len(s.Languages) > 1
|
|
|
|
}
|
|
|
|
|
2018-03-30 14:15:22 -04:00
|
|
|
func (s *SiteInfo) IsServer() bool {
|
|
|
|
return s.owner.running
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
type siteRefLinker struct {
|
|
|
|
s *Site
|
|
|
|
|
|
|
|
errorLogger *log.Logger
|
|
|
|
notFoundURL string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSiteRefLinker(cfg config.Provider, s *Site) (siteRefLinker, error) {
|
2020-10-21 05:17:48 -04:00
|
|
|
logger := s.Log.Error()
|
2018-07-18 13:58:39 -04:00
|
|
|
|
|
|
|
notFoundURL := cfg.GetString("refLinksNotFoundURL")
|
|
|
|
errLevel := cfg.GetString("refLinksErrorLevel")
|
|
|
|
if strings.EqualFold(errLevel, "warning") {
|
2020-10-21 05:17:48 -04:00
|
|
|
logger = s.Log.Warn()
|
2018-07-18 13:58:39 -04:00
|
|
|
}
|
|
|
|
return siteRefLinker{s: s, errorLogger: logger, notFoundURL: notFoundURL}, nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s siteRefLinker) logNotFound(ref, what string, p page.Page, position text.Position) {
|
2018-11-01 06:28:30 -04:00
|
|
|
if position.IsValid() {
|
|
|
|
s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q: %s: %s", s.s.Lang(), ref, position.String(), what)
|
|
|
|
} else if p == nil {
|
2018-08-24 03:23:01 -04:00
|
|
|
s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q: %s", s.s.Lang(), ref, what)
|
2018-07-18 13:58:39 -04:00
|
|
|
} else {
|
2022-01-04 07:07:10 -05:00
|
|
|
s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q from page %q: %s", s.s.Lang(), ref, p.Pathc(), what)
|
2018-07-18 13:58:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *siteRefLinker) refLink(ref string, source any, relative bool, outputFormat string) (string, error) {
|
2019-01-02 06:33:26 -05:00
|
|
|
p, err := unwrapPage(source)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2018-11-01 06:28:30 -04:00
|
|
|
}
|
2018-07-18 13:58:39 -04:00
|
|
|
|
2015-03-11 13:34:57 -04:00
|
|
|
var refURL *url.URL
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
|
2017-07-15 05:05:14 -04:00
|
|
|
ref = filepath.ToSlash(ref)
|
|
|
|
|
2015-03-11 13:34:57 -04:00
|
|
|
refURL, err = url.Parse(ref)
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
|
|
|
|
if err != nil {
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.notFoundURL, err
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
var target page.Page
|
2015-03-07 06:53:20 -05:00
|
|
|
var link string
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
|
2015-03-11 13:34:57 -04:00
|
|
|
if refURL.Path != "" {
|
2019-11-06 03:20:59 -05:00
|
|
|
var err error
|
2019-09-10 05:26:34 -04:00
|
|
|
target, err = s.s.getPageRef(p, refURL.Path)
|
2018-11-01 06:28:30 -04:00
|
|
|
var pos text.Position
|
|
|
|
if err != nil || target == nil {
|
|
|
|
if p, ok := source.(text.Positioner); ok {
|
|
|
|
pos = p.Position()
|
|
|
|
}
|
|
|
|
}
|
2018-05-29 21:35:27 -04:00
|
|
|
|
|
|
|
if err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.logNotFound(refURL.Path, err.Error(), p, pos)
|
2018-07-19 11:17:35 -04:00
|
|
|
return s.notFoundURL, nil
|
2018-05-29 21:35:27 -04:00
|
|
|
}
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
|
|
|
|
if target == nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.logNotFound(refURL.Path, "page not found", p, pos)
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.notFoundURL, nil
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
}
|
|
|
|
|
2017-04-04 12:14:41 -04:00
|
|
|
var permalinker Permalinker = target
|
|
|
|
|
|
|
|
if outputFormat != "" {
|
|
|
|
o := target.OutputFormats().Get(outputFormat)
|
|
|
|
|
|
|
|
if o == nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.logNotFound(refURL.Path, fmt.Sprintf("output format %q", outputFormat), p, pos)
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.notFoundURL, nil
|
2017-04-04 12:14:41 -04:00
|
|
|
}
|
|
|
|
permalinker = o
|
|
|
|
}
|
|
|
|
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
if relative {
|
2017-04-04 12:14:41 -04:00
|
|
|
link = permalinker.RelPermalink()
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
} else {
|
2017-04-04 12:14:41 -04:00
|
|
|
link = permalinker.Permalink()
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 13:34:57 -04:00
|
|
|
if refURL.Fragment != "" {
|
2019-08-16 09:55:03 -04:00
|
|
|
_ = target
|
2015-03-11 13:34:57 -04:00
|
|
|
link = link + "#" + refURL.Fragment
|
2019-11-06 03:20:59 -05:00
|
|
|
|
2019-08-16 09:55:03 -04:00
|
|
|
if pctx, ok := target.(pageContext); ok {
|
2019-01-02 06:33:26 -05:00
|
|
|
if refURL.Path != "" {
|
2019-08-16 09:55:03 -04:00
|
|
|
if di, ok := pctx.getContentConverter().(converter.DocumentInfo); ok {
|
|
|
|
link = link + di.AnchorSuffix()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if pctx, ok := p.(pageContext); ok {
|
|
|
|
if di, ok := pctx.getContentConverter().(converter.DocumentInfo); ok {
|
|
|
|
link = link + di.AnchorSuffix()
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2019-08-16 09:55:03 -04:00
|
|
|
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
return link, nil
|
|
|
|
}
|
|
|
|
|
2016-04-07 14:03:03 -04:00
|
|
|
func (s *Site) running() bool {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.h != nil && s.h.running
|
2013-10-25 18:03:14 -04:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
func (s *Site) multilingual() *Multilingual {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.h.multilingual
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2016-08-12 18:33:17 -04:00
|
|
|
type whatChanged struct {
|
|
|
|
source bool
|
2018-01-28 05:46:48 -05:00
|
|
|
files map[string]bool
|
2016-08-12 18:33:17 -04:00
|
|
|
}
|
|
|
|
|
2017-04-04 12:05:19 -04:00
|
|
|
// RegisterMediaTypes will register the Site's media types in the mime
|
|
|
|
// package, so it will behave correctly with Hugo's built-in server.
|
|
|
|
func (s *Site) RegisterMediaTypes() {
|
|
|
|
for _, mt := range s.mediaTypesConfig {
|
2021-03-11 03:18:01 -05:00
|
|
|
for _, suffix := range mt.Suffixes() {
|
2018-07-10 05:55:22 -04:00
|
|
|
_ = mime.AddExtensionType(mt.Delimiter+suffix, mt.Type()+"; charset=utf-8")
|
|
|
|
}
|
2017-04-04 12:05:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
func (s *Site) filterFileEvents(events []fsnotify.Event) []fsnotify.Event {
|
|
|
|
var filtered []fsnotify.Event
|
|
|
|
seen := make(map[fsnotify.Event]bool)
|
|
|
|
|
|
|
|
for _, ev := range events {
|
|
|
|
// Avoid processing the same event twice.
|
|
|
|
if seen[ev] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seen[ev] = true
|
|
|
|
|
|
|
|
if s.SourceSpec.IgnoreFile(ev.Name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Throw away any directories
|
|
|
|
isRegular, err := s.SourceSpec.IsRegularSourceFile(ev.Name)
|
2022-12-14 06:20:13 -05:00
|
|
|
if err != nil && herrors.IsNotExist(err) && (ev.Op&fsnotify.Remove == fsnotify.Remove || ev.Op&fsnotify.Rename == fsnotify.Rename) {
|
: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
|
|
|
// Force keep of event
|
|
|
|
isRegular = true
|
|
|
|
}
|
|
|
|
if !isRegular {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:35:30 -05:00
|
|
|
if runtime.GOOS == "darwin" { // When a file system is HFS+, its filepath is in NFD form.
|
|
|
|
ev.Name = norm.NFC.String(ev.Name)
|
|
|
|
}
|
|
|
|
|
: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
|
|
|
filtered = append(filtered, ev)
|
|
|
|
}
|
|
|
|
|
|
|
|
return filtered
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) translateFileEvents(events []fsnotify.Event) []fsnotify.Event {
|
|
|
|
var filtered []fsnotify.Event
|
|
|
|
|
|
|
|
eventMap := make(map[string][]fsnotify.Event)
|
|
|
|
|
|
|
|
// We often get a Remove etc. followed by a Create, a Create followed by a Write.
|
2020-12-16 06:11:32 -05:00
|
|
|
// Remove the superfluous events to mage the update logic simpler.
|
: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
|
|
|
for _, ev := range events {
|
|
|
|
eventMap[ev.Name] = append(eventMap[ev.Name], ev)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ev := range events {
|
|
|
|
mapped := eventMap[ev.Name]
|
|
|
|
|
|
|
|
// Keep one
|
|
|
|
found := false
|
|
|
|
var kept fsnotify.Event
|
|
|
|
for i, ev2 := range mapped {
|
|
|
|
if i == 0 {
|
|
|
|
kept = ev2
|
|
|
|
}
|
|
|
|
|
|
|
|
if ev2.Op&fsnotify.Write == fsnotify.Write {
|
|
|
|
kept = ev2
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found && ev2.Op&fsnotify.Create == fsnotify.Create {
|
|
|
|
kept = ev2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filtered = append(filtered, kept)
|
|
|
|
}
|
|
|
|
|
|
|
|
return filtered
|
|
|
|
}
|
|
|
|
|
2020-10-05 07:34:14 -04:00
|
|
|
var (
|
|
|
|
// These are only used for cache busting, so false positives are fine.
|
|
|
|
// We also deliberately do not match for file suffixes to also catch
|
|
|
|
// directory names.
|
|
|
|
// TODO(bep) consider this when completing the relevant PR rewrite on this.
|
|
|
|
cssFileRe = regexp.MustCompile("(css|sass|scss)")
|
|
|
|
cssConfigRe = regexp.MustCompile(`(postcss|tailwind)\.config\.js`)
|
|
|
|
jsFileRe = regexp.MustCompile("(js|ts|jsx|tsx)")
|
|
|
|
)
|
|
|
|
|
2016-08-08 03:05:16 -04:00
|
|
|
// reBuild partially rebuilds a site given the filesystem events.
|
2020-12-16 06:11:32 -05:00
|
|
|
// It returns whatever the content source was changed.
|
: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
|
|
|
// TODO(bep) clean up/rewrite this method.
|
2019-08-03 11:27:40 -04:00
|
|
|
func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) error, events []fsnotify.Event) error {
|
: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
|
|
|
events = s.filterFileEvents(events)
|
|
|
|
events = s.translateFileEvents(events)
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
changeIdentities := make(identity.Identities)
|
|
|
|
|
2021-06-07 10:36:48 -04:00
|
|
|
s.Log.Debugf("Rebuild for events %q", events)
|
2016-07-26 08:44:37 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
h := s.h
|
2016-07-26 08:44:37 -04:00
|
|
|
|
2015-12-22 00:10:01 -05:00
|
|
|
// First we need to determine what changed
|
|
|
|
|
: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
|
|
|
var (
|
|
|
|
sourceChanged = []fsnotify.Event{}
|
|
|
|
sourceReallyChanged = []fsnotify.Event{}
|
|
|
|
contentFilesChanged []string
|
2019-11-27 07:42:36 -05:00
|
|
|
|
|
|
|
tmplChanged bool
|
2019-12-20 02:11:36 -05:00
|
|
|
tmplAdded bool
|
2019-11-27 07:42:36 -05:00
|
|
|
dataChanged bool
|
|
|
|
i18nChanged bool
|
|
|
|
|
|
|
|
sourceFilesChanged = make(map[string]bool)
|
: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
|
|
|
|
|
|
|
// prevent spamming the log on changes
|
2021-06-07 10:36:48 -04:00
|
|
|
logger = helpers.NewDistinctErrorLogger()
|
: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
|
|
|
)
|
2016-01-28 09:31:25 -05:00
|
|
|
|
2019-08-13 06:35:04 -04:00
|
|
|
var cachePartitions []string
|
2020-09-20 07:34:45 -04:00
|
|
|
// Special case
|
|
|
|
// TODO(bep) I have a ongoing branch where I have redone the cache. Consider this there.
|
2020-10-05 07:34:14 -04:00
|
|
|
var (
|
|
|
|
evictCSSRe *regexp.Regexp
|
|
|
|
evictJSRe *regexp.Regexp
|
|
|
|
)
|
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
|
|
|
|
2019-08-13 06:35:04 -04:00
|
|
|
for _, ev := range events {
|
2020-11-13 02:54:29 -05:00
|
|
|
if assetsFilename, _ := s.BaseFs.Assets.MakePathRelative(ev.Name); assetsFilename != "" {
|
2019-08-13 06:35:04 -04:00
|
|
|
cachePartitions = append(cachePartitions, resources.ResourceKeyPartitions(assetsFilename)...)
|
2020-10-05 07:34:14 -04:00
|
|
|
if evictCSSRe == nil {
|
|
|
|
if cssFileRe.MatchString(assetsFilename) || cssConfigRe.MatchString(assetsFilename) {
|
|
|
|
evictCSSRe = cssFileRe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if evictJSRe == nil && jsFileRe.MatchString(assetsFilename) {
|
|
|
|
evictJSRe = jsFileRe
|
2020-09-20 07:34:45 -04:00
|
|
|
}
|
2019-08-13 06:35:04 -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
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
id, found := s.eventToIdentity(ev)
|
|
|
|
if found {
|
|
|
|
changeIdentities[id] = id
|
|
|
|
|
|
|
|
switch id.Type {
|
|
|
|
case files.ComponentFolderContent:
|
|
|
|
logger.Println("Source changed", ev)
|
|
|
|
sourceChanged = append(sourceChanged, ev)
|
|
|
|
case files.ComponentFolderLayouts:
|
|
|
|
tmplChanged = true
|
2020-01-15 09:59:56 -05:00
|
|
|
if !s.Tmpl().HasTemplate(id.Path) {
|
2019-12-20 02:11:36 -05:00
|
|
|
tmplAdded = true
|
|
|
|
}
|
|
|
|
if tmplAdded {
|
|
|
|
logger.Println("Template added", ev)
|
|
|
|
} else {
|
|
|
|
logger.Println("Template changed", ev)
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
case files.ComponentFolderData:
|
|
|
|
logger.Println("Data changed", ev)
|
|
|
|
dataChanged = true
|
|
|
|
case files.ComponentFolderI18n:
|
|
|
|
logger.Println("i18n changed", ev)
|
|
|
|
i18nChanged = true
|
|
|
|
|
2017-03-10 14:54:50 -05:00
|
|
|
}
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
changed := &whatChanged{
|
2019-11-27 07:42:36 -05:00
|
|
|
source: len(sourceChanged) > 0,
|
2019-08-03 11:27:40 -04:00
|
|
|
files: sourceFilesChanged,
|
|
|
|
}
|
|
|
|
|
|
|
|
config.whatChanged = changed
|
|
|
|
|
|
|
|
if err := init(config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// These in memory resource caches will be rebuilt on demand.
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, s := range s.h.Sites {
|
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
|
|
|
s.ResourceSpec.ResourceCache.DeletePartitions(cachePartitions...)
|
2020-10-05 07:34:14 -04:00
|
|
|
if evictCSSRe != nil {
|
|
|
|
s.ResourceSpec.ResourceCache.DeleteMatches(evictCSSRe)
|
|
|
|
}
|
|
|
|
if evictJSRe != nil {
|
|
|
|
s.ResourceSpec.ResourceCache.DeleteMatches(evictJSRe)
|
2020-09-20 07:34:45 -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
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
if tmplChanged || i18nChanged {
|
2019-01-02 06:33:26 -05:00
|
|
|
sites := s.h.Sites
|
2017-01-10 04:55:03 -05:00
|
|
|
first := sites[0]
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
s.h.init.Reset()
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// TOD(bep) globals clean
|
2017-02-04 22:20:06 -05:00
|
|
|
if err := first.Deps.LoadResources(); err != nil {
|
2019-08-03 11:27:40 -04:00
|
|
|
return err
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := 1; i < len(sites); i++ {
|
|
|
|
site := sites[i]
|
|
|
|
var err 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
|
|
|
depsCfg := deps.DepsCfg{
|
2019-01-02 06:33:26 -05:00
|
|
|
Language: site.language,
|
2018-08-05 05:13:49 -04:00
|
|
|
MediaTypes: site.mediaTypesConfig,
|
|
|
|
OutputFormats: site.outputFormatsConfig,
|
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
|
|
|
}
|
2018-11-26 04:11:22 -05:00
|
|
|
site.Deps, err = first.Deps.ForLanguage(depsCfg, func(d *deps.Deps) error {
|
2019-09-10 05:26:34 -04:00
|
|
|
d.Site = site.Info
|
2018-11-26 04:11:22 -05:00
|
|
|
return nil
|
|
|
|
})
|
2017-01-10 04:55:03 -05:00
|
|
|
if err != nil {
|
2019-08-03 11:27:40 -04:00
|
|
|
return err
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
if dataChanged {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.h.init.data.Reset()
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
|
|
|
|
2016-03-17 10:51:52 -04:00
|
|
|
for _, ev := range sourceChanged {
|
: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
|
|
|
removed := false
|
|
|
|
|
2016-03-17 10:51:52 -04:00
|
|
|
if ev.Op&fsnotify.Remove == fsnotify.Remove {
|
: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
|
|
|
removed = true
|
2016-03-17 10:51:52 -04:00
|
|
|
}
|
2016-01-25 14:40:44 -05:00
|
|
|
|
2016-03-17 10:51:52 -04:00
|
|
|
// Some editors (Vim) sometimes issue only a Rename operation when writing an existing file
|
|
|
|
// Sometimes a rename operation means that file has been renamed other times it means
|
|
|
|
// it's been updated
|
|
|
|
if ev.Op&fsnotify.Rename == fsnotify.Rename {
|
|
|
|
// If the file is still on disk, it's only been updated, if it's not, it's been moved
|
2017-01-10 04:55:03 -05:00
|
|
|
if ex, err := afero.Exists(s.Fs.Source, ev.Name); !ex || err != nil {
|
: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
|
|
|
removed = true
|
2016-01-11 12:06:52 -05:00
|
|
|
}
|
2016-03-17 10:51:52 -04:00
|
|
|
}
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
|
|
|
if removed && files.IsContentFile(ev.Name) {
|
2018-03-21 12:21:46 -04:00
|
|
|
h.removePageByFilename(ev.Name)
|
2017-06-07 16:31:57 -04:00
|
|
|
}
|
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
sourceReallyChanged = append(sourceReallyChanged, ev)
|
2018-01-28 05:46:48 -05:00
|
|
|
sourceFilesChanged[ev.Name] = true
|
2016-03-17 10:51:52 -04:00
|
|
|
}
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
if config.ErrRecovery || tmplAdded || dataChanged {
|
2019-12-20 02:11:36 -05:00
|
|
|
h.resetPageState()
|
|
|
|
} else {
|
|
|
|
h.resetPageStateFromEvents(changeIdentities)
|
|
|
|
}
|
2017-03-10 14:54:50 -05:00
|
|
|
|
: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
|
|
|
if len(sourceReallyChanged) > 0 || len(contentFilesChanged) > 0 {
|
|
|
|
var filenamesChanged []string
|
|
|
|
for _, e := range sourceReallyChanged {
|
|
|
|
filenamesChanged = append(filenamesChanged, e.Name)
|
|
|
|
}
|
|
|
|
if len(contentFilesChanged) > 0 {
|
|
|
|
filenamesChanged = append(filenamesChanged, contentFilesChanged...)
|
|
|
|
}
|
2016-01-07 21:48:13 -05: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
|
|
|
filenamesChanged = helpers.UniqueStringsReuse(filenamesChanged)
|
2016-01-07 21:48:13 -05:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
if err := s.readAndProcessContent(*config, filenamesChanged...); err != nil {
|
2019-08-03 11:27:40 -04:00
|
|
|
return err
|
2016-09-23 13:04:19 -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
|
|
|
|
2016-09-23 13:04:19 -04:00
|
|
|
}
|
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
return nil
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) process(config BuildCfg) (err error) {
|
|
|
|
if err = s.initialize(); err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
err = fmt.Errorf("initialize: %w", err)
|
2019-01-02 06:33:26 -05:00
|
|
|
return
|
: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
|
|
|
}
|
2021-10-13 02:12:06 -04:00
|
|
|
if err = s.readAndProcessContent(config); err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
err = fmt.Errorf("readAndProcessContent: %w", err)
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
return
|
2018-10-22 11:42:06 -04:00
|
|
|
}
|
|
|
|
return err
|
2015-01-20 17:08:01 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) render(ctx *siteRenderContext) (err error) {
|
|
|
|
if err := page.Clear(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-05 03:24:37 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if ctx.outIdx == 0 {
|
2017-06-20 04:30:40 -04:00
|
|
|
// Note that even if disableAliases is set, the aliases themselves are
|
|
|
|
// preserved on page. The motivation with this is to be able to generate
|
|
|
|
// 301 redirects in a .htacess file and similar using a custom output format.
|
|
|
|
if !s.Cfg.GetBool("disableAliases") {
|
|
|
|
// Aliases must be rendered before pages.
|
|
|
|
// Some sites, Hugo docs included, have faulty alias definitions that point
|
|
|
|
// to itself or another real page. These will be overwritten in the next
|
|
|
|
// step.
|
|
|
|
if err = s.renderAliases(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2017-05-05 03:24:37 -04:00
|
|
|
}
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err = s.renderPages(ctx); err != nil {
|
2014-01-29 17:50:31 -05:00
|
|
|
return
|
|
|
|
}
|
2017-05-05 03:24:37 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if ctx.outIdx == 0 {
|
|
|
|
if err = s.renderSitemap(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2016-11-08 17:34:52 -05:00
|
|
|
|
2020-06-20 09:00:25 -04:00
|
|
|
if ctx.multihost {
|
|
|
|
if err = s.renderRobotsTXT(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2016-11-08 17:34:52 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err = s.render404(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2014-05-06 06:50:23 -04:00
|
|
|
}
|
2015-12-08 16:13:09 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if !ctx.renderSingletonPages() {
|
2015-12-08 16:13:09 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err = s.renderMainLanguageRedirect(); err != nil {
|
2016-11-08 17:34:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-01-29 17:50:31 -05:00
|
|
|
return
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:20:58 -04:00
|
|
|
func (s *Site) Initialise() (err error) {
|
|
|
|
return s.initialize()
|
|
|
|
}
|
|
|
|
|
2013-09-25 00:24:49 -04:00
|
|
|
func (s *Site) initialize() (err error) {
|
2018-05-04 04:18:45 -04:00
|
|
|
return s.initializeSiteInfo()
|
2013-09-12 19:17:53 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 10:11:03 -04:00
|
|
|
// HomeAbsURL is a convenience method giving the absolute URL to the home page.
|
2016-08-04 16:12:19 -04:00
|
|
|
func (s *SiteInfo) HomeAbsURL() string {
|
2016-08-07 16:01:55 -04:00
|
|
|
base := ""
|
2016-08-07 08:03:03 -04:00
|
|
|
if s.IsMultiLingual() {
|
2018-11-26 04:11:22 -05:00
|
|
|
base = s.Language().Lang
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
2017-01-10 04:55:03 -05:00
|
|
|
return s.owner.AbsURL(base, false)
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// SitemapAbsURL is a convenience method giving the absolute URL to the sitemap.
|
|
|
|
func (s *SiteInfo) SitemapAbsURL() string {
|
2016-09-30 10:24:09 -04:00
|
|
|
p := s.HomeAbsURL()
|
|
|
|
if !strings.HasSuffix(p, "/") {
|
|
|
|
p += "/"
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
p += s.s.siteCfg.sitemap.Filename
|
2016-09-30 10:24:09 -04:00
|
|
|
return p
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
|
|
|
|
2018-05-04 04:18:45 -04:00
|
|
|
func (s *Site) initializeSiteInfo() error {
|
2016-07-24 07:58:27 -04:00
|
|
|
var (
|
2019-01-02 06:33:26 -05:00
|
|
|
lang = s.language
|
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
|
|
|
languages langs.Languages
|
2016-07-24 07:58:27 -04:00
|
|
|
)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if s.h != nil && s.h.multilingual != nil {
|
|
|
|
languages = s.h.multilingual.Languages
|
2016-07-24 07:58:27 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
permalinks := s.Cfg.GetStringMapString("permalinks")
|
2014-04-05 01:26:43 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
defaultContentInSubDir := s.Cfg.GetBool("defaultContentLanguageInSubdir")
|
|
|
|
defaultContentLanguage := s.Cfg.GetString("defaultContentLanguage")
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2016-05-14 00:35:16 -04:00
|
|
|
languagePrefix := ""
|
2016-08-08 07:55:18 -04:00
|
|
|
if s.multilingualEnabled() && (defaultContentInSubDir || lang.Lang != defaultContentLanguage) {
|
2016-07-24 07:58:27 -04:00
|
|
|
languagePrefix = "/" + lang.Lang
|
2016-05-14 00:35:16 -04:00
|
|
|
}
|
|
|
|
|
2020-12-02 07:23:25 -05:00
|
|
|
uglyURLs := func(p page.Page) bool {
|
2018-01-11 11:46:43 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
v := s.Cfg.Get("uglyURLs")
|
|
|
|
if v != nil {
|
2018-01-28 11:03:10 -05:00
|
|
|
switch vv := v.(type) {
|
|
|
|
case bool:
|
2019-01-02 06:33:26 -05:00
|
|
|
uglyURLs = func(p page.Page) bool {
|
2018-01-11 11:46:43 -05:00
|
|
|
return vv
|
|
|
|
}
|
2018-01-28 11:03:10 -05:00
|
|
|
case string:
|
|
|
|
// Is what be get from CLI (--uglyURLs)
|
|
|
|
vvv := cast.ToBool(vv)
|
2019-01-02 06:33:26 -05:00
|
|
|
uglyURLs = func(p page.Page) bool {
|
2018-01-28 11:03:10 -05:00
|
|
|
return vvv
|
|
|
|
}
|
|
|
|
default:
|
2021-06-09 04:58:18 -04:00
|
|
|
m := maps.ToStringMapBool(v)
|
2019-01-02 06:33:26 -05:00
|
|
|
uglyURLs = func(p page.Page) bool {
|
2018-01-11 11:46:43 -05:00
|
|
|
return m[p.Section()]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 09:07:04 -05:00
|
|
|
// Assemble dependencies to be used in hugo.Deps.
|
|
|
|
// TODO(bep) another reminder: We need to clean up this Site vs HugoSites construct.
|
|
|
|
var deps []*hugo.Dependency
|
|
|
|
var depFromMod func(m modules.Module) *hugo.Dependency
|
|
|
|
depFromMod = func(m modules.Module) *hugo.Dependency {
|
|
|
|
dep := &hugo.Dependency{
|
|
|
|
Path: m.Path(),
|
|
|
|
Version: m.Version(),
|
|
|
|
Time: m.Time(),
|
|
|
|
Vendor: m.Vendor(),
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are pointers, but this all came from JSON so there's no recursive navigation,
|
|
|
|
// so just create new values.
|
|
|
|
if m.Replace() != nil {
|
|
|
|
dep.Replace = depFromMod(m.Replace())
|
|
|
|
}
|
|
|
|
if m.Owner() != nil {
|
|
|
|
dep.Owner = depFromMod(m.Owner())
|
|
|
|
}
|
|
|
|
return dep
|
|
|
|
}
|
|
|
|
for _, m := range s.Paths.AllModules {
|
|
|
|
deps = append(deps, depFromMod(m))
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
s.Info = &SiteInfo{
|
2019-01-02 06:33:26 -05:00
|
|
|
title: lang.GetString("title"),
|
2016-09-18 13:10:11 -04:00
|
|
|
Author: lang.GetStringMap("author"),
|
2016-08-08 07:55:18 -04:00
|
|
|
Social: lang.GetStringMapString("social"),
|
2016-10-24 14:56:00 -04:00
|
|
|
LanguageCode: lang.GetString("languageCode"),
|
2016-08-08 07:55:18 -04:00
|
|
|
Copyright: lang.GetString("copyright"),
|
2018-11-26 04:11:22 -05:00
|
|
|
language: lang,
|
2016-08-08 07:55:18 -04:00
|
|
|
LanguagePrefix: languagePrefix,
|
|
|
|
Languages: languages,
|
|
|
|
defaultContentLanguageInSubdir: defaultContentInSubDir,
|
2016-11-23 16:06:15 -05:00
|
|
|
sectionPagesMenu: lang.GetString("sectionPagesMenu"),
|
2017-02-04 22:20:06 -05:00
|
|
|
BuildDrafts: s.Cfg.GetBool("buildDrafts"),
|
|
|
|
canonifyURLs: s.Cfg.GetBool("canonifyURLs"),
|
2017-02-20 03:52:06 -05:00
|
|
|
relativeURLs: s.Cfg.GetBool("relativeURLs"),
|
2018-01-11 11:46:43 -05:00
|
|
|
uglyURLs: uglyURLs,
|
2019-01-02 06:33:26 -05:00
|
|
|
permalinks: permalinks,
|
|
|
|
owner: s.h,
|
2017-01-10 04:55:03 -05:00
|
|
|
s: s,
|
2022-01-11 09:07:04 -05:00
|
|
|
hugoInfo: hugo.NewInfo(s.Cfg.GetString("environment"), deps),
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
2016-10-24 07:45:30 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
rssOutputFormat, found := s.outputFormats[page.KindHome].GetByName(output.RSSFormat.Name)
|
2017-05-17 12:57:44 -04:00
|
|
|
|
|
|
|
if found {
|
|
|
|
s.Info.RSSLink = s.permalink(rssOutputFormat.BaseFilename())
|
|
|
|
}
|
2018-05-04 04:18:45 -04:00
|
|
|
|
|
|
|
return nil
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
func (s *Site) eventToIdentity(e fsnotify.Event) (identity.PathIdentity, bool) {
|
|
|
|
for _, fs := range s.BaseFs.SourceFilesystems.FileSystems() {
|
|
|
|
if p := fs.Path(e.Name); p != "" {
|
2020-01-15 09:59:56 -05:00
|
|
|
return identity.NewPathIdentity(fs.Name, filepath.ToSlash(p)), true
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return identity.PathIdentity{}, false
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
func (s *Site) readAndProcessContent(buildConfig BuildCfg, filenames ...string) error {
|
|
|
|
sourceSpec := source.NewSourceSpec(s.PathSpec, buildConfig.ContentInclusionFilter, s.BaseFs.Content.Fs)
|
2018-03-21 12:21:46 -04:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
proc := newPagesProcessor(s.h, sourceSpec)
|
2016-01-08 18:37:37 -05:00
|
|
|
|
2020-06-16 04:42:41 -04:00
|
|
|
c := newPagesCollector(sourceSpec, s.h.getContentMaps(), s.Log, s.h.ContentChanges, proc, filenames...)
|
2016-01-07 21:48:13 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if err := c.Collect(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) getMenusFromConfig() navigation.Menus {
|
|
|
|
ret := navigation.Menus{}
|
2014-04-24 18:11:08 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if menus := s.language.GetStringMap("menus"); menus != nil {
|
2014-04-24 18:11:08 -04:00
|
|
|
for name, menu := range menus {
|
|
|
|
m, err := cast.ToSliceE(menu)
|
|
|
|
if err != nil {
|
2022-02-24 05:14:32 -05:00
|
|
|
s.Log.Errorf("menus in site config contain errors\n")
|
2020-10-21 05:17:48 -04:00
|
|
|
s.Log.Errorln(err)
|
2014-04-24 18:11:08 -04:00
|
|
|
} else {
|
2021-07-30 04:56:45 -04:00
|
|
|
handleErr := func(err error) {
|
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
2022-02-24 05:14:32 -05:00
|
|
|
s.Log.Errorf("menus in site config contain errors\n")
|
2021-07-30 04:56:45 -04:00
|
|
|
s.Log.Errorln(err)
|
|
|
|
}
|
|
|
|
|
2014-04-24 18:11:08 -04:00
|
|
|
for _, entry := range m {
|
2021-06-07 10:36:48 -04:00
|
|
|
s.Log.Debugf("found menu: %q, in site config\n", name)
|
2014-04-24 18:11:08 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
menuEntry := navigation.MenuEntry{Menu: name}
|
2019-11-21 15:59:38 -05:00
|
|
|
ime, err := maps.ToStringMapE(entry)
|
2021-07-30 04:56:45 -04:00
|
|
|
handleErr(err)
|
|
|
|
|
|
|
|
err = menuEntry.MarshallMap(ime)
|
|
|
|
handleErr(err)
|
2014-04-24 18:11:08 -04:00
|
|
|
|
2019-04-19 03:18:12 -04:00
|
|
|
// TODO(bep) clean up all of this
|
|
|
|
menuEntry.ConfiguredURL = s.Info.createNodeMenuEntryURL(menuEntry.ConfiguredURL)
|
2014-12-12 14:28:28 -05:00
|
|
|
|
2014-04-24 18:11:08 -04:00
|
|
|
if ret[name] == nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
ret[name] = navigation.Menu{}
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
ret[name] = ret[name].Add(&menuEntry)
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-05-09 14:54:11 -04:00
|
|
|
func (s *SiteInfo) createNodeMenuEntryURL(in string) string {
|
|
|
|
if !strings.HasPrefix(in, "/") {
|
|
|
|
return in
|
|
|
|
}
|
|
|
|
// make it match the nodes
|
|
|
|
menuEntryURL := in
|
2017-01-10 04:55:03 -05:00
|
|
|
menuEntryURL = helpers.SanitizeURLKeepTrailingSlash(s.s.PathSpec.URLize(menuEntryURL))
|
2015-05-09 14:54:11 -04:00
|
|
|
if !s.canonifyURLs {
|
2021-06-18 04:27:27 -04:00
|
|
|
menuEntryURL = paths.AddContextRoot(s.s.PathSpec.BaseURL.String(), menuEntryURL)
|
2015-05-09 14:54:11 -04:00
|
|
|
}
|
|
|
|
return menuEntryURL
|
|
|
|
}
|
|
|
|
|
2014-04-23 02:59:19 -04:00
|
|
|
func (s *Site) assembleMenus() {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.menus = make(navigation.Menus)
|
2014-04-23 02:59:19 -04:00
|
|
|
|
|
|
|
type twoD struct {
|
|
|
|
MenuName, EntryName string
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
flat := map[twoD]*navigation.MenuEntry{}
|
|
|
|
children := map[twoD]navigation.Menu{}
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2017-01-22 06:28:31 -05:00
|
|
|
// add menu entries from config to flat hash
|
2014-04-24 18:11:08 -04:00
|
|
|
menuConfig := s.getMenusFromConfig()
|
|
|
|
for name, menu := range menuConfig {
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, me := range menu {
|
2021-07-20 06:10:22 -04:00
|
|
|
if types.IsNil(me.Page) && me.PageRef != "" {
|
|
|
|
// Try to resolve the page.
|
|
|
|
me.Page, _ = s.getPageNew(nil, me.PageRef)
|
|
|
|
}
|
2014-05-14 18:01:13 -04:00
|
|
|
flat[twoD{name, me.KeyName()}] = me
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 16:06:15 -05:00
|
|
|
sectionPagesMenu := s.Info.sectionPagesMenu
|
2017-01-22 06:28:31 -05:00
|
|
|
|
|
|
|
if sectionPagesMenu != "" {
|
2022-03-17 17:03:27 -04:00
|
|
|
s.pageMap.sections.Walk(func(s string, v any) bool {
|
2019-09-10 05:26:34 -04:00
|
|
|
p := v.(*contentNode).p
|
|
|
|
if p.IsHome() {
|
|
|
|
return false
|
2017-01-22 06:28:31 -05:00
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
// From Hugo 0.22 we have nested sections, but until we get a
|
|
|
|
// feel of how that would work in this setting, let us keep
|
|
|
|
// this menu for the top level only.
|
|
|
|
id := p.Section()
|
|
|
|
if _, ok := flat[twoD{sectionPagesMenu, id}]; ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-12-02 07:23:25 -05:00
|
|
|
me := navigation.MenuEntry{
|
|
|
|
Identifier: id,
|
|
|
|
Name: p.LinkTitle(),
|
|
|
|
Weight: p.Weight(),
|
|
|
|
Page: p,
|
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
flat[twoD{sectionPagesMenu, me.KeyName()}] = &me
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
2017-01-22 06:28:31 -05:00
|
|
|
}
|
2015-01-06 12:11:06 -05:00
|
|
|
|
2017-01-22 06:28:31 -05:00
|
|
|
// Add menu entries provided by pages
|
2019-09-10 05:26:34 -04:00
|
|
|
s.pageMap.pageTrees.WalkRenderable(func(ss string, n *contentNode) bool {
|
|
|
|
p := n.p
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
for name, me := range p.pageMenus.menus() {
|
2014-05-14 18:01:13 -04:00
|
|
|
if _, ok := flat[twoD{name, me.KeyName()}]; ok {
|
2022-05-02 10:07:52 -04:00
|
|
|
err := p.wrapError(fmt.Errorf("duplicate menu entry with identifier %q in menu %q", me.KeyName(), name))
|
2020-10-21 05:17:48 -04:00
|
|
|
s.Log.Warnln(err)
|
2015-01-22 11:23:01 -05:00
|
|
|
continue
|
2014-05-14 18:01:13 -04:00
|
|
|
}
|
|
|
|
flat[twoD{name, me.KeyName()}] = me
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
2014-04-23 02:59:19 -04:00
|
|
|
|
|
|
|
// Create Children Menus First
|
|
|
|
for _, e := range flat {
|
|
|
|
if e.Parent != "" {
|
2019-01-02 06:33:26 -05:00
|
|
|
children[twoD{e.Menu, e.Parent}] = children[twoD{e.Menu, e.Parent}].Add(e)
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placing Children in Parents (in flat)
|
|
|
|
for p, childmenu := range children {
|
|
|
|
_, ok := flat[twoD{p.MenuName, p.EntryName}]
|
|
|
|
if !ok {
|
2015-03-18 01:16:54 -04:00
|
|
|
// if parent does not exist, create one without a URL
|
2019-04-19 03:18:12 -04:00
|
|
|
flat[twoD{p.MenuName, p.EntryName}] = &navigation.MenuEntry{Name: p.EntryName}
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
|
|
|
flat[twoD{p.MenuName, p.EntryName}].Children = childmenu
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assembling Top Level of Tree
|
|
|
|
for menu, e := range flat {
|
|
|
|
if e.Parent == "" {
|
2019-01-02 06:33:26 -05:00
|
|
|
_, ok := s.menus[menu.MenuName]
|
2014-04-23 02:59:19 -04:00
|
|
|
if !ok {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.menus[menu.MenuName] = navigation.Menu{}
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
s.menus[menu.MenuName] = s.menus[menu.MenuName].Add(e)
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 06:11:32 -05:00
|
|
|
// get any language code to prefix the target file path with.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) getLanguageTargetPathLang(alwaysInSubDir bool) string {
|
|
|
|
if s.h.IsMultihost() {
|
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.getLanguagePermalinkLang(alwaysInSubDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// get any lanaguagecode to prefix the relative permalink with.
|
|
|
|
func (s *Site) getLanguagePermalinkLang(alwaysInSubDir bool) string {
|
|
|
|
if !s.Info.IsMultiLingual() || s.h.IsMultihost() {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if alwaysInSubDir {
|
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
|
|
|
isDefault := s.Language().Lang == s.multilingual().DefaultLang.Lang
|
|
|
|
|
|
|
|
if !isDefault || s.Info.defaultContentLanguageInSubdir {
|
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
func (s *Site) getTaxonomyKey(key string) string {
|
2019-01-02 06:33:26 -05:00
|
|
|
if s.PathSpec.DisablePathToLower {
|
|
|
|
return s.PathSpec.MakePath(key)
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return strings.ToLower(s.PathSpec.MakePath(key))
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
2017-02-18 04:02:12 -05:00
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
// Prepare site for a new full build.
|
2019-08-03 11:27:40 -04:00
|
|
|
func (s *Site) resetBuildState(sourceChanged bool) {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.relatedDocsHandler = s.relatedDocsHandler.Clone()
|
|
|
|
s.init.Reset()
|
2016-03-06 10:33:32 -05:00
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
if sourceChanged {
|
2020-09-07 09:07:10 -04:00
|
|
|
s.pageMap.contentMap.pageReverseIndex.Reset()
|
2019-09-10 05:26:34 -04:00
|
|
|
s.PageCollections = newPageCollections(s.pageMap)
|
|
|
|
s.pageMap.withEveryBundlePage(func(p *pageState) bool {
|
2019-08-03 11:27:40 -04:00
|
|
|
p.pagePages = &pagePages{}
|
2020-03-22 08:42:39 -04:00
|
|
|
if p.bucket != nil {
|
|
|
|
p.bucket.pagesMapBucketPages = &pagesMapBucketPages{}
|
|
|
|
}
|
2019-08-03 11:27:40 -04:00
|
|
|
p.parent = nil
|
|
|
|
p.Scratcher = maps.NewScratcher()
|
2019-09-10 05:26:34 -04:00
|
|
|
return false
|
|
|
|
})
|
2019-08-03 11:27:40 -04:00
|
|
|
} else {
|
2019-09-10 05:26:34 -04:00
|
|
|
s.pageMap.withEveryBundlePage(func(p *pageState) bool {
|
2019-08-03 11:27:40 -04:00
|
|
|
p.Scratcher = maps.NewScratcher()
|
2019-09-10 05:26:34 -04:00
|
|
|
return false
|
2019-08-03 11:27:40 -04:00
|
|
|
})
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
2018-10-03 08:58:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) errorCollator(results <-chan error, errs chan<- error) {
|
|
|
|
var errors []error
|
|
|
|
for e := range results {
|
|
|
|
errors = append(errors, e)
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
errs <- s.h.pickOneAndLogTheRest(errors)
|
2018-10-03 08:58:09 -04:00
|
|
|
|
|
|
|
close(errs)
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
|
|
|
|
2018-05-29 21:35:27 -04:00
|
|
|
// GetPage looks up a page of a given type for the given ref.
|
2018-07-17 05:18:29 -04:00
|
|
|
// In Hugo <= 0.44 you had to add Page Kind (section, home) etc. as the first
|
|
|
|
// argument and then either a unix styled path (with or without a leading slash))
|
|
|
|
// or path elements separated.
|
|
|
|
// When we now remove the Kind from this API, we need to make the transition as painless
|
|
|
|
// as possible for existing sites. Most sites will use {{ .Site.GetPage "section" "my/section" }},
|
|
|
|
// i.e. 2 arguments, so we test for that.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) GetPage(ref ...string) (page.Page, error) {
|
|
|
|
p, err := s.s.getPageOldVersion(ref...)
|
2016-11-12 11:30:21 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if p == nil {
|
|
|
|
// The nil struct has meaning in some situations, mostly to avoid breaking
|
|
|
|
// existing sites doing $nilpage.IsDescendant($p), which will always return
|
|
|
|
// false.
|
|
|
|
p = page.NilPage
|
2017-03-23 15:05:10 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
return p, err
|
2017-03-23 15:05:10 -04:00
|
|
|
}
|
|
|
|
|
2020-09-07 09:07:10 -04:00
|
|
|
func (s *SiteInfo) GetPageWithTemplateInfo(info tpl.Info, ref ...string) (page.Page, error) {
|
|
|
|
p, err := s.GetPage(ref...)
|
|
|
|
if p != nil {
|
|
|
|
// Track pages referenced by templates/shortcodes
|
|
|
|
// when in server mode.
|
|
|
|
if im, ok := info.(identity.Manager); ok {
|
|
|
|
im.Add(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p, err
|
|
|
|
}
|
|
|
|
|
2017-03-09 13:19:29 -05:00
|
|
|
func (s *Site) permalink(link string) string {
|
: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
|
|
|
return s.PathSpec.PermalinkForBaseURL(link, s.PathSpec.BaseURL.String())
|
2020-06-14 05:14:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) absURLPath(targetPath string) string {
|
|
|
|
var path string
|
|
|
|
if s.Info.relativeURLs {
|
|
|
|
path = helpers.GetDottedRelativePath(targetPath)
|
|
|
|
} else {
|
|
|
|
url := s.PathSpec.BaseURL.String()
|
|
|
|
if !strings.HasSuffix(url, "/") {
|
|
|
|
url += "/"
|
|
|
|
}
|
|
|
|
path = url
|
|
|
|
}
|
2017-03-23 15:05:10 -04:00
|
|
|
|
2020-06-14 05:14:56 -04:00
|
|
|
return path
|
2017-03-23 15:05:10 -04:00
|
|
|
}
|
2014-10-18 14:25:10 -04:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
func (s *Site) lookupLayouts(layouts ...string) tpl.Template {
|
|
|
|
for _, l := range layouts {
|
|
|
|
if templ, found := s.Tmpl().Lookup(l); found {
|
|
|
|
return templ
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *Site) renderAndWriteXML(statCounter *uint64, name string, targetPath string, d any, templ tpl.Template) error {
|
2021-06-07 10:36:48 -04:00
|
|
|
s.Log.Debugf("Render XML for %q to %q", name, targetPath)
|
2015-01-30 14:51:06 -05:00
|
|
|
renderBuffer := bp.GetBuffer()
|
|
|
|
defer bp.PutBuffer(renderBuffer)
|
2014-12-18 14:59:39 -05:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
if err := s.renderForTemplate(name, "", d, renderBuffer, templ); err != nil {
|
2018-10-03 08:58:09 -04:00
|
|
|
return err
|
2016-07-25 16:22:09 -04:00
|
|
|
}
|
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
pd := publisher.Descriptor{
|
|
|
|
Src: renderBuffer,
|
|
|
|
TargetPath: targetPath,
|
|
|
|
StatCounter: statCounter,
|
|
|
|
// For the minification part of XML,
|
|
|
|
// we currently only use the MIME type.
|
|
|
|
OutputFormat: output.RSSFormat,
|
2020-06-14 05:14:56 -04:00
|
|
|
AbsURLPath: s.absURLPath(targetPath),
|
2017-04-06 11:39:20 -04:00
|
|
|
}
|
2015-01-30 14:51:06 -05:00
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
return s.publisher.Publish(pd)
|
2014-11-04 00:39:37 -05:00
|
|
|
}
|
2013-10-01 22:58:15 -04:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath string, p *pageState, templ tpl.Template) error {
|
2021-06-07 10:36:48 -04:00
|
|
|
s.Log.Debugf("Render %s to %q", name, targetPath)
|
2022-02-09 07:41:04 -05:00
|
|
|
s.h.IncrPageRender()
|
2015-01-30 15:05:05 -05:00
|
|
|
renderBuffer := bp.GetBuffer()
|
|
|
|
defer bp.PutBuffer(renderBuffer)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
of := p.outputFormat()
|
2018-10-03 08:58:09 -04:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
if err := s.renderForTemplate(p.Kind(), of.Name, p, renderBuffer, templ); err != nil {
|
2018-10-03 08:58:09 -04:00
|
|
|
return err
|
2016-07-25 16:22:09 -04:00
|
|
|
}
|
|
|
|
|
2017-04-23 16:03:25 -04:00
|
|
|
if renderBuffer.Len() == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
isHTML := of.IsHTML
|
|
|
|
isRSS := of.Name == "RSS"
|
2014-01-29 17:50:31 -05:00
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
pd := publisher.Descriptor{
|
|
|
|
Src: renderBuffer,
|
|
|
|
TargetPath: targetPath,
|
|
|
|
StatCounter: statCounter,
|
2019-01-02 06:33:26 -05:00
|
|
|
OutputFormat: p.outputFormat(),
|
2018-08-05 05:13:49 -04:00
|
|
|
}
|
2014-01-29 17:50:31 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if isRSS {
|
|
|
|
// Always canonify URLs in RSS
|
2020-06-14 05:14:56 -04:00
|
|
|
pd.AbsURLPath = s.absURLPath(targetPath)
|
2019-01-02 06:33:26 -05:00
|
|
|
} else if isHTML {
|
2017-04-07 05:01:36 -04:00
|
|
|
if s.Info.relativeURLs || s.Info.canonifyURLs {
|
2020-06-14 05:14:56 -04:00
|
|
|
pd.AbsURLPath = s.absURLPath(targetPath)
|
2017-04-07 05:01:36 -04:00
|
|
|
}
|
2014-05-16 17:49:27 -04:00
|
|
|
|
2017-04-07 05:01:36 -04:00
|
|
|
if s.running() && s.Cfg.GetBool("watch") && !s.Cfg.GetBool("disableLiveReload") {
|
2020-12-02 06:52:26 -05:00
|
|
|
pd.LiveReloadBaseURL = s.PathSpec.BaseURL.URL()
|
|
|
|
if s.Cfg.GetInt("liveReloadPort") != -1 {
|
|
|
|
pd.LiveReloadBaseURL.Host = fmt.Sprintf("%s:%d", pd.LiveReloadBaseURL.Hostname(), s.Cfg.GetInt("liveReloadPort"))
|
|
|
|
}
|
2017-04-07 05:01:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// For performance reasons we only inject the Hugo generator tag on the home page.
|
|
|
|
if p.IsHome() {
|
2018-08-05 05:13:49 -04:00
|
|
|
pd.AddHugoGeneratorTag = !s.Cfg.GetBool("disableHugoGeneratorInject")
|
2015-05-15 18:11:39 -04:00
|
|
|
}
|
|
|
|
|
2017-04-06 11:39:20 -04:00
|
|
|
}
|
2015-01-30 15:05:05 -05:00
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
return s.publisher.Publish(pd)
|
2014-11-04 00:39:37 -05:00
|
|
|
}
|
2014-01-29 17:50:31 -05:00
|
|
|
|
Make WARN the new default log log level
This commit also pulls down the log level for a set of WARN statements to INFO. There should be no ERRORs or WARNINGs in a regular Hugo build. That is the story about the Boy Who Cried Wolf.
Since the WARN log is now more visible, this commit also improves on some of them, most notable the "layout not found", which now would look something like this:
```bash
WARN 2018/11/02 09:02:18 Found no layout for "home", language "en", output format "CSS": create a template below /layouts with one of these filenames: index.en.css.css, home.en.css.css, list.en.css.css, index.css.css, home.css.css, list.css.css, index.en.css, home.en.css, list.en.css, index.css, home.css, list.css, _default/index.en.css.css, _default/home.en.css.css, _default/list.en.css.css, _default/index.css.css, _default/home.css.css, _default/list.css.css, _default/index.en.css, _default/home.en.css, _default/list.en.css, _default/index.css, _default/home.css, _default/list.css
```
Fixes #5203
2018-11-01 17:27:42 -04:00
|
|
|
var infoOnMissingLayout = map[string]bool{
|
|
|
|
// The 404 layout is very much optional in Hugo, but we do look for it.
|
|
|
|
"404": true,
|
|
|
|
}
|
|
|
|
|
2022-02-17 07:04:00 -05:00
|
|
|
// hookRendererTemplate is the canonical implementation of all hooks.ITEMRenderer,
|
2020-03-14 10:43:10 -04:00
|
|
|
// where ITEM is the thing being hooked.
|
2022-02-17 07:04:00 -05:00
|
|
|
type hookRendererTemplate struct {
|
2019-11-27 07:42:36 -05:00
|
|
|
templateHandler tpl.TemplateHandler
|
2020-11-26 02:32:49 -05:00
|
|
|
identity.SearchProvider
|
2022-02-26 06:52:06 -05:00
|
|
|
templ tpl.Template
|
2022-03-17 17:03:27 -04:00
|
|
|
resolvePosition func(ctx any) text.Position
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
2022-02-17 07:04:00 -05:00
|
|
|
func (hr hookRendererTemplate) RenderLink(w io.Writer, ctx hooks.LinkContext) error {
|
|
|
|
return hr.templateHandler.Execute(hr.templ, w, ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hr hookRendererTemplate) RenderHeading(w io.Writer, ctx hooks.HeadingContext) error {
|
2020-03-14 10:43:10 -04:00
|
|
|
return hr.templateHandler.Execute(hr.templ, w, ctx)
|
|
|
|
}
|
|
|
|
|
2022-02-17 07:04:00 -05:00
|
|
|
func (hr hookRendererTemplate) RenderCodeblock(w hugio.FlexiWriter, ctx hooks.CodeblockContext) error {
|
2020-03-14 10:43:10 -04:00
|
|
|
return hr.templateHandler.Execute(hr.templ, w, ctx)
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (hr hookRendererTemplate) ResolvePosition(ctx any) text.Position {
|
2022-02-26 06:52:06 -05:00
|
|
|
return hr.resolvePosition(ctx)
|
|
|
|
}
|
|
|
|
|
2022-02-26 11:24:10 -05:00
|
|
|
func (hr hookRendererTemplate) IsDefaultCodeBlockRenderer() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (s *Site) renderForTemplate(name, outputFormat string, d any, w io.Writer, templ tpl.Template) (err error) {
|
2017-03-27 14:43:49 -04:00
|
|
|
if templ == nil {
|
2020-09-13 14:36:37 -04:00
|
|
|
s.logMissingLayout(name, "", "", outputFormat)
|
2018-10-03 08:58:09 -04:00
|
|
|
return nil
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
if err = s.Tmpl().Execute(templ, w, d); err != nil {
|
2022-05-02 10:07:52 -04:00
|
|
|
return fmt.Errorf("render of %q failed: %w", name, err)
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
2017-07-14 04:26:51 -04:00
|
|
|
return
|
2013-10-01 22:58:15 -04:00
|
|
|
}
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
func (s *Site) lookupTemplate(layouts ...string) (tpl.Template, bool) {
|
|
|
|
for _, l := range layouts {
|
|
|
|
if templ, found := s.Tmpl().Lookup(l); found {
|
|
|
|
return templ, true
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
|
|
|
}
|
2020-01-15 09:59:56 -05:00
|
|
|
|
|
|
|
return nil, false
|
2013-08-27 05:09:50 -04:00
|
|
|
}
|
|
|
|
|
2022-03-14 11:02:04 -04:00
|
|
|
func (s *Site) publish(statCounter *uint64, path string, r io.Reader, fs afero.Fs) (err error) {
|
: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
|
|
|
s.PathSpec.ProcessingStats.Incr(statCounter)
|
|
|
|
|
2022-03-14 11:02:04 -04:00
|
|
|
return helpers.WriteToDisk(filepath.Clean(path), r, fs)
|
2017-03-16 04:09:26 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) kindFromFileInfoOrSections(fi *fileInfo, sections []string) string {
|
|
|
|
if fi.TranslationBaseName() == "_index" {
|
|
|
|
if fi.Dir() == "" {
|
|
|
|
return page.KindHome
|
2014-08-29 13:40:21 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
return s.kindFromSections(sections)
|
|
|
|
|
2014-08-29 13:40:21 -04:00
|
|
|
}
|
2019-09-10 05:26:34 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return page.KindPage
|
2014-08-29 13:40:21 -04:00
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) kindFromSections(sections []string) string {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
if len(sections) == 0 {
|
|
|
|
return page.KindHome
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2017-03-17 11:35:09 -04:00
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
return s.kindFromSectionPath(path.Join(sections...))
|
|
|
|
}
|
2017-03-17 11:35:09 -04:00
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
func (s *Site) kindFromSectionPath(sectionPath string) string {
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, plural := range s.siteCfg.taxonomiesConfig {
|
|
|
|
if plural == sectionPath {
|
2020-06-16 09:43:50 -04:00
|
|
|
return page.KindTaxonomy
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2017-03-06 07:18:33 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if strings.HasPrefix(sectionPath, plural) {
|
2020-06-16 09:43:50 -04:00
|
|
|
return page.KindTerm
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return page.KindSection
|
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
func (s *Site) newPage(
|
|
|
|
n *contentNode,
|
|
|
|
parentbBucket *pagesMapBucket,
|
|
|
|
kind, title string,
|
|
|
|
sections ...string) *pageState {
|
2022-03-17 17:03:27 -04:00
|
|
|
m := map[string]any{}
|
2019-09-10 05:26:34 -04:00
|
|
|
if title != "" {
|
|
|
|
m["title"] = title
|
2016-11-16 15:06:10 -05:00
|
|
|
}
|
|
|
|
|
2019-08-09 04:05:22 -04:00
|
|
|
p, err := newPageFromMeta(
|
2019-09-10 05:26:34 -04:00
|
|
|
n,
|
|
|
|
parentbBucket,
|
|
|
|
m,
|
2019-08-09 04:05:22 -04:00
|
|
|
&pageMeta{
|
|
|
|
s: s,
|
|
|
|
kind: kind,
|
|
|
|
sections: sections,
|
|
|
|
})
|
2019-01-02 06:33:26 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2016-11-16 15:06:10 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2016-11-16 15:06:10 -05:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) shouldBuild(p page.Page) bool {
|
|
|
|
return shouldBuild(s.BuildFuture, s.BuildExpired,
|
|
|
|
s.BuildDrafts, p.Draft(), p.PublishDate(), p.ExpiryDate())
|
|
|
|
}
|
|
|
|
|
|
|
|
func shouldBuild(buildFuture bool, buildExpired bool, buildDrafts bool, Draft bool,
|
|
|
|
publishDate time.Time, expiryDate time.Time) bool {
|
|
|
|
if !(buildDrafts || !Draft) {
|
|
|
|
return false
|
|
|
|
}
|
2022-04-26 13:57:04 -04:00
|
|
|
hnow := htime.Now()
|
|
|
|
if !buildFuture && !publishDate.IsZero() && publishDate.After(hnow) {
|
2019-01-02 06:33:26 -05:00
|
|
|
return false
|
|
|
|
}
|
2022-04-26 13:57:04 -04:00
|
|
|
if !buildExpired && !expiryDate.IsZero() && expiryDate.Before(hnow) {
|
2019-01-02 06:33:26 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2016-11-16 15:06:10 -05:00
|
|
|
}
|