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 (
|
2023-02-11 10:20:24 -05:00
|
|
|
"context"
|
2014-01-29 17:50:31 -05:00
|
|
|
"fmt"
|
|
|
|
"io"
|
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"
|
2022-01-08 05:35:30 -05:00
|
|
|
"runtime"
|
2017-04-28 03:40:50 -04:00
|
|
|
"sort"
|
2014-01-29 17:50:31 -05:00
|
|
|
"strings"
|
|
|
|
"time"
|
2014-03-31 13:23:34 -04:00
|
|
|
|
2023-06-16 02:17:42 -04:00
|
|
|
"github.com/bep/logg"
|
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-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"
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
"github.com/gohugoio/hugo/identity"
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/markup/converter/hooks"
|
|
|
|
|
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"
|
2023-05-21 08:25:16 -04:00
|
|
|
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
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
|
|
|
|
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-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"
|
|
|
|
|
2023-07-28 04:53:47 -04:00
|
|
|
"github.com/gohugoio/hugo/resources/kinds"
|
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
|
|
|
|
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"
|
|
|
|
"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"
|
2013-07-04 11:32:55 -04:00
|
|
|
)
|
|
|
|
|
2022-12-30 03:20:58 -05:00
|
|
|
func (s *Site) Taxonomies() page.TaxonomyList {
|
2023-02-11 10:20:24 -05:00
|
|
|
s.init.taxonomies.Do(context.Background())
|
2019-09-10 05:26:34 -04:00
|
|
|
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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
sitemap config.SitemapConfig
|
2019-09-10 05:26:34 -04:00
|
|
|
taxonomiesConfig taxonomiesConfig
|
2019-01-02 06:33:26 -05:00
|
|
|
timeout time.Duration
|
|
|
|
hasCJKLanguage 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
|
|
|
}
|
|
|
|
|
2023-02-11 10:20:24 -05:00
|
|
|
func (s *Site) initInit(ctx context.Context, init *lazy.Init, pctx pageContext) bool {
|
|
|
|
_, err := init.Do(ctx)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
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
|
|
|
|
|
2023-02-11 10:20:24 -05:00
|
|
|
s.init.prevNext = init.Branch(func(context.Context) (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
|
|
|
|
})
|
|
|
|
|
2023-02-11 10:20:24 -05:00
|
|
|
s.init.prevNextInSection = init.Branch(func(context.Context) (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
|
|
|
|
})
|
|
|
|
|
2023-02-11 10:20:24 -05:00
|
|
|
s.init.menus = init.Branch(func(context.Context) (any, error) {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.assembleMenus()
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
|
2023-02-11 10:20:24 -05:00
|
|
|
s.init.taxonomies = init.Branch(func(context.Context) (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 {
|
2023-02-11 10:20:24 -05:00
|
|
|
s.init.menus.Do(context.Background())
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.menus
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
func (s *Site) initRenderFormats() {
|
|
|
|
formatSet := make(map[string]bool)
|
|
|
|
formats := output.Formats{}
|
2023-01-04 12:24:36 -05:00
|
|
|
rssDisabled := !s.conf.IsKindEnabled("rss")
|
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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
if rssDisabled && f.Name == "rss" {
|
|
|
|
// legacy
|
|
|
|
continue
|
|
|
|
}
|
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
|
2023-07-28 04:53:47 -04:00
|
|
|
for _, kind := range kinds.AllKindsInPages {
|
2023-01-04 12:24:36 -05:00
|
|
|
if siteFormats, found := s.conf.C.KindOutputFormats[kind]; found {
|
2019-01-02 06:33:26 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-05-17 07:12:49 -04:00
|
|
|
func (s *Site) Languages() langs.Languages {
|
|
|
|
return s.h.Configs.Languages
|
|
|
|
}
|
|
|
|
|
2017-02-18 04:02:12 -05:00
|
|
|
func (s *Site) isEnabled(kind string) bool {
|
2023-01-04 12:24:36 -05:00
|
|
|
return s.conf.IsKindEnabled(kind)
|
2018-03-30 14:15:22 -04:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
type siteRefLinker struct {
|
|
|
|
s *Site
|
|
|
|
|
2023-06-16 02:17:42 -04:00
|
|
|
errorLogger logg.LevelLogger
|
2018-07-18 13:58:39 -04:00
|
|
|
notFoundURL string
|
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
func newSiteRefLinker(s *Site) (siteRefLinker, error) {
|
2020-10-21 05:17:48 -04:00
|
|
|
logger := s.Log.Error()
|
2018-07-18 13:58:39 -04:00
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
notFoundURL := s.conf.RefLinksNotFoundURL
|
|
|
|
errLevel := s.conf.RefLinksErrorLevel
|
2018-07-18 13:58:39 -04:00
|
|
|
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() {
|
2023-06-16 02:17:42 -04:00
|
|
|
s.errorLogger.Logf("[%s] REF_NOT_FOUND: Ref %q: %s: %s", s.s.Lang(), ref, position.String(), what)
|
2018-11-01 06:28:30 -04:00
|
|
|
} else if p == nil {
|
2023-06-16 02:17:42 -04:00
|
|
|
s.errorLogger.Logf("[%s] REF_NOT_FOUND: Ref %q: %s", s.s.Lang(), ref, what)
|
2018-07-18 13:58:39 -04:00
|
|
|
} else {
|
2023-06-16 02:17:42 -04:00
|
|
|
s.errorLogger.Logf("[%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
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:26:30 -04:00
|
|
|
func (s *Site) watching() bool {
|
|
|
|
return s.h != nil && s.h.Configs.Base.Internal.Watch
|
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() {
|
2023-01-04 12:24:36 -05:00
|
|
|
for _, mt := range s.conf.MediaTypes.Config {
|
2021-03-11 03:18:01 -05:00
|
|
|
for _, suffix := range mt.Suffixes() {
|
2023-01-04 12:24:36 -05:00
|
|
|
_ = mime.AddExtensionType(mt.Delimiter+suffix, mt.Type+"; charset=utf-8")
|
2018-07-10 05:55:22 -04:00
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
)
|
2016-01-28 09:31:25 -05:00
|
|
|
|
2023-05-21 08:25:16 -04:00
|
|
|
var cacheBusters []func(string) bool
|
|
|
|
bcfg := s.conf.Build
|
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 {
|
2023-05-21 08:25:16 -04:00
|
|
|
component, relFilename := s.BaseFs.MakePathRelative(ev.Name)
|
|
|
|
if relFilename != "" {
|
|
|
|
p := hglob.NormalizePath(path.Join(component, relFilename))
|
|
|
|
g, err := bcfg.MatchCacheBuster(s.Log, p)
|
|
|
|
if err == nil && g != nil {
|
|
|
|
cacheBusters = append(cacheBusters, g)
|
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:
|
2023-06-16 02:17:42 -04:00
|
|
|
s.Log.Println("Source changed", ev)
|
2019-11-27 07:42:36 -05:00
|
|
|
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 {
|
2023-06-16 02:17:42 -04:00
|
|
|
s.Log.Println("Template added", ev)
|
2019-12-20 02:11:36 -05:00
|
|
|
} else {
|
2023-06-16 02:17:42 -04:00
|
|
|
s.Log.Println("Template changed", ev)
|
2019-12-20 02:11:36 -05:00
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
case files.ComponentFolderData:
|
2023-06-16 02:17:42 -04:00
|
|
|
s.Log.Println("Data changed", ev)
|
2019-11-27 07:42:36 -05:00
|
|
|
dataChanged = true
|
|
|
|
case files.ComponentFolderI18n:
|
2023-06-16 02:17:42 -04:00
|
|
|
s.Log.Println("i18n changed", ev)
|
2019-11-27 07:42:36 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-05-21 08:25:16 -04:00
|
|
|
var cacheBusterOr func(string) bool
|
|
|
|
if len(cacheBusters) > 0 {
|
|
|
|
cacheBusterOr = func(s string) bool {
|
|
|
|
for _, cb := range cacheBusters {
|
|
|
|
if cb(s) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
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
|
|
|
}
|
|
|
|
|
2023-05-21 08:25:16 -04:00
|
|
|
// These in memory resource caches will be rebuilt on demand.
|
|
|
|
if len(cacheBusters) > 0 {
|
|
|
|
s.h.ResourceSpec.ResourceCache.DeleteMatches(cacheBusterOr)
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
if tmplChanged || i18nChanged {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.h.init.Reset()
|
2023-01-04 12:24:36 -05:00
|
|
|
var prototype *deps.Deps
|
|
|
|
for i, s := range s.h.Sites {
|
|
|
|
if err := s.Deps.Compile(prototype); err != nil {
|
2019-08-03 11:27:40 -04:00
|
|
|
return err
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
2023-01-04 12:24:36 -05:00
|
|
|
if i == 0 {
|
|
|
|
prototype = s.Deps
|
|
|
|
}
|
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) {
|
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.
|
2023-01-04 12:24:36 -05:00
|
|
|
if !s.conf.DisableAliases {
|
2017-06-20 04:30:40 -04:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2016-08-05 10:11:03 -04:00
|
|
|
// HomeAbsURL is a convenience method giving the absolute URL to the home page.
|
2023-01-04 12:24:36 -05:00
|
|
|
func (s *Site) HomeAbsURL() string {
|
2016-08-07 16:01:55 -04:00
|
|
|
base := ""
|
2023-01-04 12:24:36 -05:00
|
|
|
if len(s.conf.Languages) > 1 {
|
2018-11-26 04:11:22 -05:00
|
|
|
base = s.Language().Lang
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
2023-01-04 12:24:36 -05:00
|
|
|
return s.AbsURL(base, false)
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// SitemapAbsURL is a convenience method giving the absolute URL to the sitemap.
|
2023-01-04 12:24:36 -05:00
|
|
|
func (s *Site) SitemapAbsURL() string {
|
2016-09-30 10:24:09 -04:00
|
|
|
p := s.HomeAbsURL()
|
|
|
|
if !strings.HasSuffix(p, "/") {
|
|
|
|
p += "/"
|
|
|
|
}
|
2023-01-04 12:24:36 -05:00
|
|
|
p += s.conf.Sitemap.Filename
|
2016-09-30 10:24:09 -04:00
|
|
|
return p
|
2016-08-04 16:12:19 -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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
if s.Deps == nil {
|
|
|
|
panic("nil deps on site")
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
func (s *Site) createNodeMenuEntryURL(in string) string {
|
2015-05-09 14:54:11 -04:00
|
|
|
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))
|
2023-01-04 12:24:36 -05:00
|
|
|
if !s.conf.CanonifyURLs {
|
|
|
|
menuEntryURL = paths.AddContextRoot(s.s.PathSpec.Cfg.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
|
2023-01-04 12:24:36 -05:00
|
|
|
for name, menu := range s.conf.Menus.Config {
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, me := range menu {
|
2023-01-04 12:24:36 -05:00
|
|
|
if types.IsNil(me.Page) {
|
|
|
|
if me.PageRef != "" {
|
|
|
|
// Try to resolve the page.
|
|
|
|
p, _ := s.getPageNew(nil, me.PageRef)
|
|
|
|
if !types.IsNil(p) {
|
|
|
|
navigation.SetPageValues(me, p)
|
|
|
|
}
|
|
|
|
}
|
2023-06-02 01:59:50 -04:00
|
|
|
}
|
2023-01-04 12:24:36 -05:00
|
|
|
|
2023-06-02 01:59:50 -04:00
|
|
|
// If page is still nill, we must make sure that we have a URL that considers baseURL etc.
|
|
|
|
if types.IsNil(me.Page) {
|
2023-01-04 12:24:36 -05:00
|
|
|
me.ConfiguredURL = s.createNodeMenuEntryURL(me.MenuConfig.URL)
|
2021-07-20 06:10:22 -04:00
|
|
|
}
|
2023-01-04 12:24:36 -05:00
|
|
|
|
2014-05-14 18:01:13 -04:00
|
|
|
flat[twoD{name, me.KeyName()}] = me
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
sectionPagesMenu := s.conf.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{
|
2023-01-04 12:24:36 -05:00
|
|
|
MenuConfig: navigation.MenuConfig{
|
|
|
|
Identifier: id,
|
|
|
|
Name: p.LinkTitle(),
|
|
|
|
Weight: p.Weight(),
|
|
|
|
},
|
2020-12-02 07:23:25 -05:00
|
|
|
}
|
2023-01-04 12:24:36 -05:00
|
|
|
navigation.SetPageValues(&me, 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
|
2023-01-04 12:24:36 -05:00
|
|
|
flat[twoD{p.MenuName, p.EntryName}] = &navigation.MenuEntry{
|
|
|
|
MenuConfig: navigation.MenuConfig{
|
|
|
|
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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
if s.h.Conf.IsMultihost() {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.getLanguagePermalinkLang(alwaysInSubDir)
|
|
|
|
}
|
|
|
|
|
2023-05-22 13:11:12 -04:00
|
|
|
// get any language code to prefix the relative permalink with.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) getLanguagePermalinkLang(alwaysInSubDir bool) string {
|
2023-07-07 12:41:10 -04:00
|
|
|
if s.h.Conf.IsMultihost() {
|
2019-01-02 06:33:26 -05:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-07-07 12:41:10 -04:00
|
|
|
if s.h.Conf.IsMultiLingual() && alwaysInSubDir {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
2023-07-07 12:41:10 -04:00
|
|
|
return s.GetLanguagePrefix()
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
func (s *Site) getTaxonomyKey(key string) string {
|
2023-01-04 12:24:36 -05:00
|
|
|
if s.conf.DisablePathToLower {
|
2019-01-02 06:33:26 -05:00
|
|
|
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.
|
2023-01-04 12:24:36 -05:00
|
|
|
func (s *Site) GetPage(ref ...string) (page.Page, error) {
|
2019-01-02 06:33:26 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-04 12:24:36 -05:00
|
|
|
func (s *Site) GetPageWithTemplateInfo(info tpl.Info, ref ...string) (page.Page, error) {
|
2020-09-07 09:07:10 -04:00
|
|
|
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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
return s.PathSpec.PermalinkForBaseURL(link, s.PathSpec.Cfg.BaseURL().String())
|
2020-06-14 05:14:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) absURLPath(targetPath string) string {
|
|
|
|
var path string
|
2023-01-04 12:24:36 -05:00
|
|
|
if s.conf.RelativeURLs {
|
2020-06-14 05:14:56 -04:00
|
|
|
path = helpers.GetDottedRelativePath(targetPath)
|
|
|
|
} else {
|
2023-01-04 12:24:36 -05:00
|
|
|
url := s.PathSpec.Cfg.BaseURL().String()
|
2020-06-14 05:14:56 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
func (s *Site) renderAndWriteXML(ctx context.Context, statCounter *uint64, name string, targetPath string, d any, templ tpl.Template) error {
|
2015-01-30 14:51:06 -05:00
|
|
|
renderBuffer := bp.GetBuffer()
|
|
|
|
defer bp.PutBuffer(renderBuffer)
|
2014-12-18 14:59:39 -05:00
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
if err := s.renderForTemplate(ctx, 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 {
|
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()
|
2023-02-25 03:24:59 -05:00
|
|
|
ctx := tpl.SetPageInContext(context.Background(), p)
|
2018-10-03 08:58:09 -04:00
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
if err := s.renderForTemplate(ctx, 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
|
2023-01-04 12:24:36 -05:00
|
|
|
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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
if s.conf.RelativeURLs || s.conf.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
|
|
|
|
2023-07-19 03:23:48 -04:00
|
|
|
if s.watching() && s.conf.Internal.Running && !s.conf.DisableLiveReload {
|
2023-01-04 12:24:36 -05:00
|
|
|
pd.LiveReloadBaseURL = s.Conf.BaseURLLiveReload().URL()
|
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() {
|
2023-01-04 12:24:36 -05:00
|
|
|
pd.AddHugoGeneratorTag = !s.conf.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
|
|
|
}
|
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
func (hr hookRendererTemplate) RenderLink(cctx context.Context, w io.Writer, ctx hooks.LinkContext) error {
|
|
|
|
return hr.templateHandler.ExecuteWithContext(cctx, hr.templ, w, ctx)
|
2022-02-17 07:04:00 -05:00
|
|
|
}
|
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
func (hr hookRendererTemplate) RenderHeading(cctx context.Context, w io.Writer, ctx hooks.HeadingContext) error {
|
|
|
|
return hr.templateHandler.ExecuteWithContext(cctx, hr.templ, w, ctx)
|
2020-03-14 10:43:10 -04:00
|
|
|
}
|
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
func (hr hookRendererTemplate) RenderCodeblock(cctx context.Context, w hugio.FlexiWriter, ctx hooks.CodeblockContext) error {
|
|
|
|
return hr.templateHandler.ExecuteWithContext(cctx, 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
|
|
|
|
}
|
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
func (s *Site) renderForTemplate(ctx context.Context, 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
|
|
|
}
|
|
|
|
|
2023-02-25 03:24:59 -05:00
|
|
|
if ctx == nil {
|
|
|
|
panic("nil context")
|
|
|
|
}
|
2023-02-11 10:20:24 -05:00
|
|
|
|
|
|
|
if err = s.Tmpl().ExecuteWithContext(ctx, 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() == "" {
|
2023-07-28 04:53:47 -04:00
|
|
|
return kinds.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
|
|
|
|
2023-07-28 04:53:47 -04:00
|
|
|
return kinds.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 {
|
2023-07-28 04:53:47 -04:00
|
|
|
return kinds.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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
var taxonomiesConfig taxonomiesConfig = s.conf.Taxonomies
|
|
|
|
for _, plural := range taxonomiesConfig {
|
2019-01-02 06:33:26 -05:00
|
|
|
if plural == sectionPath {
|
2023-07-28 04:53:47 -04:00
|
|
|
return kinds.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) {
|
2023-07-28 04:53:47 -04:00
|
|
|
return kinds.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
|
|
|
|
2023-07-28 04:53:47 -04:00
|
|
|
return kinds.KindSection
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
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 {
|
2023-01-04 12:24:36 -05:00
|
|
|
return shouldBuild(s.Conf.BuildFuture(), s.Conf.BuildExpired(),
|
|
|
|
s.Conf.BuildDrafts(), p.Draft(), p.PublishDate(), p.ExpiryDate())
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|