2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2013-07-04 11:32:55 -04:00
|
|
|
//
|
2015-11-23 22:16:36 -05:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
2013-07-04 11:32:55 -04:00
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-11-23 22:16:36 -05:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-04 11:32:55 -04:00
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
2014-01-29 17:50:31 -05:00
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"io"
|
2018-07-18 13:58:39 -04:00
|
|
|
"log"
|
2017-04-04 12:05:19 -04:00
|
|
|
"mime"
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
"net/url"
|
2014-01-29 17:50:31 -05:00
|
|
|
"os"
|
2019-01-02 06:33:26 -05:00
|
|
|
"path"
|
2014-12-27 08:11:19 -05:00
|
|
|
"path/filepath"
|
2017-04-28 03:40:50 -04:00
|
|
|
"sort"
|
2014-08-29 13:40:21 -04:00
|
|
|
"strconv"
|
2014-01-29 17:50:31 -05:00
|
|
|
"strings"
|
|
|
|
"time"
|
2014-03-31 13:23:34 -04:00
|
|
|
|
2019-08-16 09:55:03 -04:00
|
|
|
"github.com/gohugoio/hugo/markup/converter"
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"github.com/gohugoio/hugo/hugofs/files"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/common/maps"
|
|
|
|
|
2018-11-07 02:36:35 -05:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
2018-11-01 06:28:30 -04:00
|
|
|
"github.com/gohugoio/hugo/common/text"
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hugo"
|
2018-08-05 05:13:49 -04:00
|
|
|
"github.com/gohugoio/hugo/publisher"
|
2018-11-26 04:11:22 -05:00
|
|
|
_errors "github.com/pkg/errors"
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
"github.com/gohugoio/hugo/langs"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/config"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/lazy"
|
2017-04-04 03:12:33 -04:00
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/media"
|
2015-01-30 14:51:06 -05:00
|
|
|
|
2016-04-20 10:28:26 -04:00
|
|
|
"github.com/fsnotify/fsnotify"
|
2017-06-13 12:42:45 -04:00
|
|
|
bp "github.com/gohugoio/hugo/bufferpool"
|
|
|
|
"github.com/gohugoio/hugo/deps"
|
|
|
|
"github.com/gohugoio/hugo/helpers"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/navigation"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/output"
|
2017-08-19 07:16:00 -04:00
|
|
|
"github.com/gohugoio/hugo/related"
|
2019-01-02 05:58:32 -05:00
|
|
|
"github.com/gohugoio/hugo/resources"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page/pagemeta"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/source"
|
|
|
|
"github.com/gohugoio/hugo/tpl"
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2017-06-13 13:07:35 -04:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/cast"
|
2014-04-05 01:26:43 -04:00
|
|
|
"github.com/spf13/viper"
|
2013-07-04 11:32:55 -04:00
|
|
|
)
|
|
|
|
|
2013-10-17 23:57:25 -04:00
|
|
|
// Site contains all the information relevant for constructing a static
|
2013-09-01 00:13:04 -04:00
|
|
|
// site. The basic flow of information is as follows:
|
|
|
|
//
|
|
|
|
// 1. A list of Files is parsed and then converted into Pages.
|
|
|
|
//
|
|
|
|
// 2. Pages contain sections (based on the file they were generated from),
|
|
|
|
// aliases and slugs (included in a pages frontmatter) which are the
|
2013-11-18 04:35:56 -05:00
|
|
|
// various targets that will get generated. There will be canonical
|
|
|
|
// listing. The canonical path can be overruled based on a pattern.
|
2013-09-01 00:13:04 -04:00
|
|
|
//
|
2014-04-08 23:15:57 -04:00
|
|
|
// 3. Taxonomies are created via configuration and will present some aspect of
|
2013-09-01 00:13:04 -04:00
|
|
|
// the final page and typically a perm url.
|
|
|
|
//
|
|
|
|
// 4. All Pages are passed through a template based on their desired
|
2013-11-18 04:35:56 -05:00
|
|
|
// layout based on numerous different elements.
|
2013-09-01 00:13:04 -04:00
|
|
|
//
|
|
|
|
// 5. The entire collection of files is written to disk.
|
2013-07-04 11:32:55 -04:00
|
|
|
type Site struct {
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
// The owning container. When multiple languages, there will be multiple
|
|
|
|
// sites.
|
|
|
|
h *HugoSites
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2016-11-03 19:34:25 -04:00
|
|
|
*PageCollections
|
|
|
|
|
|
|
|
Taxonomies TaxonomyList
|
2016-10-31 14:53:33 -04:00
|
|
|
|
2017-03-03 04:47:43 -05:00
|
|
|
Sections Taxonomy
|
|
|
|
Info SiteInfo
|
|
|
|
|
2017-03-06 07:18:33 -05:00
|
|
|
layoutHandler *output.LayoutHandler
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
language *langs.Language
|
|
|
|
|
|
|
|
siteCfg siteConfigHolder
|
2017-01-03 11:28:51 -05:00
|
|
|
|
2017-02-18 04:02:12 -05:00
|
|
|
disabledKinds map[string]bool
|
|
|
|
|
2018-11-26 05:01:27 -05:00
|
|
|
enableInlineShortcodes bool
|
|
|
|
|
2017-03-22 06:34:17 -04:00
|
|
|
// Output formats defined in site config per Page Kind, or some defaults
|
|
|
|
// if not set.
|
|
|
|
// Output formats defined in Page front matter will override these.
|
|
|
|
outputFormats map[string]output.Formats
|
2017-03-09 13:19:29 -05:00
|
|
|
|
2017-04-04 03:12:33 -04:00
|
|
|
// All the output formats and media types available for this site.
|
|
|
|
// These values will be merged from the Hugo defaults, the site config and,
|
|
|
|
// finally, the language settings.
|
|
|
|
outputFormatsConfig output.Formats
|
|
|
|
mediaTypesConfig media.Types
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
siteConfigConfig SiteConfig
|
2018-07-18 13:58:39 -04:00
|
|
|
|
hugolib: Extract date and slug from filename
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter.
This should make it easier to move content from Jekyll to Hugo.
To enable, put this in your `config.toml`:
```toml
[frontmatter]
date = [":filename", ":default"]
```
This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc.
So, if you want to use the `file modification time`, this can be a good configuration:
```toml
[frontmatter]
date = [ "date",":fileModTime", ":default"]
lastmod = ["lastmod" ,":fileModTime", ":default"]
```
The current `:default` values for the different dates are
```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```
The above will now be the same as:
```toml
[frontmatter]
date = [":default"]
lastmod = [":default"]
publishDate = [":default"]
expiryDate = [":default"]
```
Note:
* We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate.
* If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved.
* All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`).
* The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values.
* The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list.
Fixes #285
Closes #3310
Closes #3762
Closes #4340
2018-03-11 06:32:55 -04:00
|
|
|
// How to handle page front matter.
|
|
|
|
frontmatterHandler pagemeta.FrontMatterHandler
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
// We render each site for all the relevant output formats in serial with
|
|
|
|
// this rendering context pointing to the current one.
|
|
|
|
rc *siteRenderingContext
|
|
|
|
|
|
|
|
// The output formats that we need to render this site in. This slice
|
|
|
|
// will be fixed once set.
|
|
|
|
// This will be the union of Site.Pages' outputFormats.
|
|
|
|
// This slice will be sorted.
|
|
|
|
renderFormats output.Formats
|
|
|
|
|
2017-01-03 11:28:51 -05:00
|
|
|
// Logger etc.
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
*deps.Deps `json:"-"`
|
2017-03-24 04:19:51 -04:00
|
|
|
|
2017-07-30 11:46:04 -04:00
|
|
|
// The func used to title case titles.
|
|
|
|
titleFunc func(s string) string
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
relatedDocsHandler *page.RelatedDocsHandler
|
2018-07-18 13:58:39 -04:00
|
|
|
siteRefLinker
|
2018-08-05 05:13:49 -04:00
|
|
|
|
|
|
|
publisher publisher.Publisher
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
menus navigation.Menus
|
|
|
|
|
|
|
|
// Shortcut to the home page. Note that this may be nil if
|
|
|
|
// home page, for some odd reason, is disabled.
|
|
|
|
home *pageState
|
|
|
|
|
|
|
|
// The last modification date of this site.
|
|
|
|
lastmod time.Time
|
|
|
|
|
|
|
|
// Lazily loaded site dependencies
|
|
|
|
init *siteInit
|
|
|
|
}
|
|
|
|
|
|
|
|
type siteConfigHolder struct {
|
|
|
|
sitemap config.Sitemap
|
|
|
|
taxonomiesConfig map[string]string
|
|
|
|
timeout time.Duration
|
|
|
|
hasCJKLanguage bool
|
|
|
|
enableEmoji bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lazily loaded site dependencies.
|
|
|
|
type siteInit struct {
|
|
|
|
prevNext *lazy.Init
|
|
|
|
prevNextInSection *lazy.Init
|
|
|
|
menus *lazy.Init
|
|
|
|
}
|
|
|
|
|
|
|
|
func (init *siteInit) Reset() {
|
|
|
|
init.prevNext.Reset()
|
|
|
|
init.prevNextInSection.Reset()
|
|
|
|
init.menus.Reset()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) initInit(init *lazy.Init, pctx pageContext) {
|
|
|
|
_, err := init.Do()
|
|
|
|
if err != nil {
|
|
|
|
s.h.FatalError(pctx.wrapError(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) prepareInits() {
|
|
|
|
s.init = &siteInit{}
|
|
|
|
|
|
|
|
var init lazy.Init
|
|
|
|
|
|
|
|
s.init.prevNext = init.Branch(func() (interface{}, error) {
|
|
|
|
regularPages := s.findWorkPagesByKind(page.KindPage)
|
|
|
|
for i, p := range regularPages {
|
|
|
|
if p.posNextPrev == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
p.posNextPrev.nextPage = nil
|
|
|
|
p.posNextPrev.prevPage = nil
|
|
|
|
|
|
|
|
if i > 0 {
|
|
|
|
p.posNextPrev.nextPage = regularPages[i-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if i < len(regularPages)-1 {
|
|
|
|
p.posNextPrev.prevPage = regularPages[i+1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.init.prevNextInSection = init.Branch(func() (interface{}, error) {
|
|
|
|
var rootSection []int
|
2019-08-03 11:27:40 -04:00
|
|
|
// TODO(bep) cm attach this to the bucket.
|
2019-01-02 06:33:26 -05:00
|
|
|
for i, p1 := range s.workAllPages {
|
|
|
|
if p1.IsPage() && p1.Section() == "" {
|
|
|
|
rootSection = append(rootSection, i)
|
|
|
|
}
|
2019-05-01 11:51:03 -04:00
|
|
|
if p1.IsSection() {
|
2019-08-03 11:27:40 -04:00
|
|
|
sectionPages := p1.RegularPages()
|
2019-01-02 06:33:26 -05:00
|
|
|
for i, p2 := range sectionPages {
|
|
|
|
p2s := p2.(*pageState)
|
|
|
|
if p2s.posNextPrevSection == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
p2s.posNextPrevSection.nextPage = nil
|
|
|
|
p2s.posNextPrevSection.prevPage = nil
|
|
|
|
|
|
|
|
if i > 0 {
|
|
|
|
p2s.posNextPrevSection.nextPage = sectionPages[i-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if i < len(sectionPages)-1 {
|
|
|
|
p2s.posNextPrevSection.prevPage = sectionPages[i+1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, j := range rootSection {
|
|
|
|
p := s.workAllPages[j]
|
|
|
|
if i > 0 {
|
|
|
|
p.posNextPrevSection.nextPage = s.workAllPages[rootSection[i-1]]
|
|
|
|
}
|
|
|
|
|
|
|
|
if i < len(rootSection)-1 {
|
|
|
|
p.posNextPrevSection.prevPage = s.workAllPages[rootSection[i+1]]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.init.menus = init.Branch(func() (interface{}, error) {
|
|
|
|
s.assembleMenus()
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
type siteRenderingContext struct {
|
|
|
|
output.Format
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) Menus() navigation.Menus {
|
|
|
|
s.init.menus.Do()
|
|
|
|
return s.menus
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
func (s *Site) initRenderFormats() {
|
|
|
|
formatSet := make(map[string]bool)
|
|
|
|
formats := output.Formats{}
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, p := range s.workAllPages {
|
|
|
|
for _, f := range p.m.configuredOutputFormats {
|
2017-04-28 03:40:50 -04:00
|
|
|
if !formatSet[f.Name] {
|
|
|
|
formats = append(formats, f)
|
|
|
|
formatSet[f.Name] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Add the per kind configured output formats
|
|
|
|
for _, kind := range allKindsInPages {
|
|
|
|
if siteFormats, found := s.outputFormats[kind]; found {
|
|
|
|
for _, f := range siteFormats {
|
|
|
|
if !formatSet[f.Name] {
|
|
|
|
formats = append(formats, f)
|
|
|
|
formatSet[f.Name] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 03:40:50 -04:00
|
|
|
sort.Sort(formats)
|
|
|
|
s.renderFormats = formats
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) GetRelatedDocsHandler() *page.RelatedDocsHandler {
|
|
|
|
return s.relatedDocsHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) Language() *langs.Language {
|
|
|
|
return s.language
|
|
|
|
}
|
|
|
|
|
2017-02-18 04:02:12 -05:00
|
|
|
func (s *Site) isEnabled(kind string) bool {
|
|
|
|
if kind == kindUnknown {
|
|
|
|
panic("Unknown kind")
|
|
|
|
}
|
|
|
|
return !s.disabledKinds[kind]
|
|
|
|
}
|
|
|
|
|
2016-08-07 18:12:06 -04:00
|
|
|
// reset returns a new Site prepared for rebuild.
|
|
|
|
func (s *Site) reset() *Site {
|
2017-03-09 13:19:29 -05:00
|
|
|
return &Site{Deps: s.Deps,
|
2018-11-26 05:01:27 -05:00
|
|
|
layoutHandler: output.NewLayoutHandler(),
|
|
|
|
disabledKinds: s.disabledKinds,
|
|
|
|
titleFunc: s.titleFunc,
|
2019-01-02 06:33:26 -05:00
|
|
|
relatedDocsHandler: s.relatedDocsHandler.Clone(),
|
2018-11-26 05:01:27 -05:00
|
|
|
siteRefLinker: s.siteRefLinker,
|
|
|
|
outputFormats: s.outputFormats,
|
|
|
|
rc: s.rc,
|
|
|
|
outputFormatsConfig: s.outputFormatsConfig,
|
|
|
|
frontmatterHandler: s.frontmatterHandler,
|
|
|
|
mediaTypesConfig: s.mediaTypesConfig,
|
2019-01-02 06:33:26 -05:00
|
|
|
language: s.language,
|
|
|
|
h: s.h,
|
2018-11-26 05:01:27 -05:00
|
|
|
publisher: s.publisher,
|
2019-01-02 06:33:26 -05:00
|
|
|
siteConfigConfig: s.siteConfigConfig,
|
2018-11-26 05:01:27 -05:00
|
|
|
enableInlineShortcodes: s.enableInlineShortcodes,
|
2019-01-02 06:33:26 -05:00
|
|
|
init: s.init,
|
2019-08-03 11:27:40 -04:00
|
|
|
PageCollections: s.PageCollections,
|
2019-01-02 06:33:26 -05:00
|
|
|
siteCfg: s.siteCfg,
|
|
|
|
}
|
2018-07-18 13:58:39 -04:00
|
|
|
|
2016-07-26 04:24:27 -04:00
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// newSite creates a new site with the given configuration.
|
|
|
|
func newSite(cfg deps.DepsCfg) (*Site, error) {
|
2016-11-03 19:34:25 -04:00
|
|
|
c := newPageCollections()
|
2017-01-09 19:36:59 -05:00
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
if cfg.Language == nil {
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
cfg.Language = langs.NewDefaultLanguage(cfg.Cfg)
|
2017-01-09 19:36:59 -05:00
|
|
|
}
|
|
|
|
|
2017-02-18 04:02:12 -05:00
|
|
|
disabledKinds := make(map[string]bool)
|
|
|
|
for _, disabled := range cast.ToStringSlice(cfg.Language.Get("disableKinds")) {
|
|
|
|
disabledKinds[disabled] = true
|
|
|
|
}
|
|
|
|
|
2017-04-04 03:12:33 -04:00
|
|
|
var (
|
|
|
|
mediaTypesConfig []map[string]interface{}
|
|
|
|
outputFormatsConfig []map[string]interface{}
|
|
|
|
|
|
|
|
siteOutputFormatsConfig output.Formats
|
|
|
|
siteMediaTypesConfig media.Types
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
// Add language last, if set, so it gets precedence.
|
|
|
|
for _, cfg := range []config.Provider{cfg.Cfg, cfg.Language} {
|
|
|
|
if cfg.IsSet("mediaTypes") {
|
|
|
|
mediaTypesConfig = append(mediaTypesConfig, cfg.GetStringMap("mediaTypes"))
|
|
|
|
}
|
|
|
|
if cfg.IsSet("outputFormats") {
|
|
|
|
outputFormatsConfig = append(outputFormatsConfig, cfg.GetStringMap("outputFormats"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
siteMediaTypesConfig, err = media.DecodeTypes(mediaTypesConfig...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
siteOutputFormatsConfig, err = output.DecodeFormats(siteMediaTypesConfig, outputFormatsConfig...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-22 06:34:17 -04:00
|
|
|
|
2017-04-04 03:12:33 -04:00
|
|
|
outputFormats, err := createSiteOutputFormats(siteOutputFormatsConfig, cfg.Language)
|
2017-03-22 06:34:17 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-09 13:19:29 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
taxonomies := cfg.Language.GetStringMapString("taxonomies")
|
|
|
|
|
2017-08-19 07:16:00 -04:00
|
|
|
var relatedContentConfig related.Config
|
|
|
|
|
|
|
|
if cfg.Language.IsSet("related") {
|
|
|
|
relatedContentConfig, err = related.DecodeConfig(cfg.Language.Get("related"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
relatedContentConfig = related.DefaultConfig
|
|
|
|
if _, found := taxonomies["tag"]; found {
|
|
|
|
relatedContentConfig.Add(related.IndexConfig{Name: "tags", Weight: 80})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-30 11:46:04 -04:00
|
|
|
titleFunc := helpers.GetTitleFunc(cfg.Language.GetString("titleCaseStyle"))
|
|
|
|
|
hugolib: Extract date and slug from filename
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter.
This should make it easier to move content from Jekyll to Hugo.
To enable, put this in your `config.toml`:
```toml
[frontmatter]
date = [":filename", ":default"]
```
This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc.
So, if you want to use the `file modification time`, this can be a good configuration:
```toml
[frontmatter]
date = [ "date",":fileModTime", ":default"]
lastmod = ["lastmod" ,":fileModTime", ":default"]
```
The current `:default` values for the different dates are
```toml
[frontmatter]
date = ["date","publishDate", "lastmod"]
lastmod = ["lastmod", "date","publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]
```
The above will now be the same as:
```toml
[frontmatter]
date = [":default"]
lastmod = [":default"]
publishDate = [":default"]
expiryDate = [":default"]
```
Note:
* We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate.
* If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved.
* All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`).
* The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values.
* The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list.
Fixes #285
Closes #3310
Closes #3762
Closes #4340
2018-03-11 06:32:55 -04:00
|
|
|
frontMatterHandler, err := pagemeta.NewFrontmatterHandler(cfg.Logger, cfg.Cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
siteConfig := siteConfigHolder{
|
|
|
|
sitemap: config.DecodeSitemap(config.Sitemap{Priority: -1, Filename: "sitemap.xml"}, cfg.Language.GetStringMap("sitemap")),
|
|
|
|
taxonomiesConfig: taxonomies,
|
|
|
|
timeout: time.Duration(cfg.Language.GetInt("timeout")) * time.Millisecond,
|
|
|
|
hasCJKLanguage: cfg.Language.GetBool("hasCJKLanguage"),
|
|
|
|
enableEmoji: cfg.Language.Cfg.GetBool("enableEmoji"),
|
|
|
|
}
|
|
|
|
|
2017-03-09 13:19:29 -05:00
|
|
|
s := &Site{
|
2018-11-26 05:01:27 -05:00
|
|
|
PageCollections: c,
|
|
|
|
layoutHandler: output.NewLayoutHandler(),
|
2019-01-02 06:33:26 -05:00
|
|
|
language: cfg.Language,
|
2018-11-26 05:01:27 -05:00
|
|
|
disabledKinds: disabledKinds,
|
|
|
|
titleFunc: titleFunc,
|
2019-01-02 06:33:26 -05:00
|
|
|
relatedDocsHandler: page.NewRelatedDocsHandler(relatedContentConfig),
|
2018-11-26 05:01:27 -05:00
|
|
|
outputFormats: outputFormats,
|
|
|
|
rc: &siteRenderingContext{output.HTMLFormat},
|
|
|
|
outputFormatsConfig: siteOutputFormatsConfig,
|
|
|
|
mediaTypesConfig: siteMediaTypesConfig,
|
|
|
|
frontmatterHandler: frontMatterHandler,
|
|
|
|
enableInlineShortcodes: cfg.Language.GetBool("enableInlineShortcodes"),
|
2019-01-02 06:33:26 -05:00
|
|
|
siteCfg: siteConfig,
|
2017-03-09 13:19:29 -05:00
|
|
|
}
|
2016-10-24 07:45:30 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
s.prepareInits()
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
return s, nil
|
2016-07-26 04:24:27 -04:00
|
|
|
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// NewSite creates a new site with the given dependency configuration.
|
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
|
|
|
func NewSite(cfg deps.DepsCfg) (*Site, error) {
|
|
|
|
s, err := newSite(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
if err = applyDeps(cfg, s); err != nil {
|
2017-01-10 04:55:03 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSiteDefaultLang creates a new site in the default language.
|
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
2018-03-18 06:07:24 -04:00
|
|
|
// TODO(bep) test refactor -- remove
|
2017-03-27 14:43:49 -04:00
|
|
|
func NewSiteDefaultLang(withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error) {
|
2017-02-04 22:20:06 -05:00
|
|
|
v := viper.New()
|
2017-09-25 02:59:02 -04:00
|
|
|
if err := loadDefaultSettingsFor(v); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return newSiteForLang(langs.NewDefaultLanguage(v), withTemplate...)
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
2017-02-15 04:00:34 -05:00
|
|
|
// NewEnglishSite creates a new site in English language.
|
2017-01-10 04:55:03 -05:00
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
2018-03-18 06:07:24 -04:00
|
|
|
// TODO(bep) test refactor -- remove
|
2017-03-27 14:43:49 -04:00
|
|
|
func NewEnglishSite(withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error) {
|
2017-02-04 22:20:06 -05:00
|
|
|
v := viper.New()
|
2017-09-25 02:59:02 -04:00
|
|
|
if err := loadDefaultSettingsFor(v); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return newSiteForLang(langs.NewLanguage("en", v), withTemplate...)
|
2017-02-15 04:00:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// newSiteForLang creates a new site in the given language.
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
func newSiteForLang(lang *langs.Language, withTemplate ...func(templ tpl.TemplateHandler) error) (*Site, error) {
|
2017-03-27 14:43:49 -04:00
|
|
|
withTemplates := func(templ tpl.TemplateHandler) error {
|
2017-01-10 04:55:03 -05:00
|
|
|
for _, wt := range withTemplate {
|
|
|
|
if err := wt(templ); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
cfg := deps.DepsCfg{WithTemplate: withTemplates, Cfg: lang}
|
2017-02-15 04:00:34 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
return NewSiteForCfg(cfg)
|
2017-02-15 04:00:34 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// NewSiteForCfg creates a new site for the given configuration.
|
|
|
|
// The site will have a template system loaded and ready to use.
|
|
|
|
// Note: This is mainly used in single site tests.
|
|
|
|
func NewSiteForCfg(cfg deps.DepsCfg) (*Site, error) {
|
2018-07-18 13:58:39 -04:00
|
|
|
h, err := NewHugoSites(cfg)
|
2017-01-10 04:55:03 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-07-18 13:58:39 -04:00
|
|
|
return h.Sites[0], nil
|
2016-10-24 07:45:30 -04:00
|
|
|
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
type SiteInfo struct {
|
|
|
|
Authors page.AuthorList
|
|
|
|
Social SiteSocial
|
2018-03-15 04:37:30 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
hugoInfo hugo.Info
|
|
|
|
title string
|
|
|
|
RSSLink string
|
|
|
|
Author map[string]interface{}
|
|
|
|
LanguageCode string
|
|
|
|
Copyright string
|
|
|
|
|
|
|
|
permalinks map[string]string
|
|
|
|
|
|
|
|
LanguagePrefix string
|
|
|
|
Languages langs.Languages
|
|
|
|
|
|
|
|
BuildDrafts bool
|
|
|
|
|
|
|
|
canonifyURLs bool
|
|
|
|
relativeURLs bool
|
|
|
|
uglyURLs func(p page.Page) bool
|
2018-03-15 04:37:30 -04:00
|
|
|
|
2016-08-09 14:06:15 -04:00
|
|
|
owner *HugoSites
|
2017-01-10 04:55:03 -05:00
|
|
|
s *Site
|
2018-11-26 04:11:22 -05:00
|
|
|
language *langs.Language
|
2016-08-08 07:55:18 -04:00
|
|
|
defaultContentLanguageInSubdir bool
|
2016-11-23 16:06:15 -05:00
|
|
|
sectionPagesMenu string
|
2014-04-23 02:52:01 -04:00
|
|
|
}
|
2014-04-23 02:55:43 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) Pages() page.Pages {
|
|
|
|
return s.s.Pages()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) RegularPages() page.Pages {
|
|
|
|
return s.s.RegularPages()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) AllPages() page.Pages {
|
|
|
|
return s.s.AllPages()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) AllRegularPages() page.Pages {
|
|
|
|
return s.s.AllRegularPages()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Permalinks() map[string]string {
|
|
|
|
// Remove in 0.57
|
|
|
|
helpers.Deprecated("Site", ".Permalinks", "", false)
|
|
|
|
return s.permalinks
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) LastChange() time.Time {
|
|
|
|
return s.s.lastmod
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Title() string {
|
|
|
|
return s.title
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Site() page.Site {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Menus() navigation.Menus {
|
|
|
|
return s.s.Menus()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(bep) type
|
|
|
|
func (s *SiteInfo) Taxonomies() interface{} {
|
|
|
|
return s.s.Taxonomies
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Params() map[string]interface{} {
|
|
|
|
return s.s.Language().Params()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SiteInfo) Data() map[string]interface{} {
|
|
|
|
return s.s.h.Data()
|
|
|
|
}
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
func (s *SiteInfo) Language() *langs.Language {
|
|
|
|
return s.language
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
func (s *SiteInfo) Config() SiteConfig {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.s.siteConfigConfig
|
2018-07-18 13:58:39 -04:00
|
|
|
}
|
|
|
|
|
2018-11-26 04:11:22 -05:00
|
|
|
func (s *SiteInfo) Hugo() hugo.Info {
|
|
|
|
return s.hugoInfo
|
|
|
|
}
|
|
|
|
|
2018-12-06 04:29:28 -05:00
|
|
|
// Sites is a convenience method to get all the Hugo sites/languages configured.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) Sites() page.Sites {
|
|
|
|
return s.s.h.siteInfos()
|
2018-12-06 04:29:28 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2016-11-13 08:27:10 -05:00
|
|
|
func (s *SiteInfo) String() string {
|
2019-01-02 06:33:26 -05:00
|
|
|
return fmt.Sprintf("Site(%q)", s.title)
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2017-04-07 12:33:28 -04:00
|
|
|
func (s *SiteInfo) BaseURL() template.URL {
|
|
|
|
return template.URL(s.s.PathSpec.BaseURL.String())
|
|
|
|
}
|
|
|
|
|
2017-11-12 04:03:56 -05:00
|
|
|
// ServerPort returns the port part of the BaseURL, 0 if none found.
|
|
|
|
func (s *SiteInfo) ServerPort() int {
|
|
|
|
ps := s.s.PathSpec.BaseURL.URL().Port()
|
|
|
|
if ps == "" {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
p, err := strconv.Atoi(ps)
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2018-05-22 08:40:06 -04:00
|
|
|
// GoogleAnalytics is kept here for historic reasons.
|
|
|
|
func (s *SiteInfo) GoogleAnalytics() string {
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.Config().Services.GoogleAnalytics.ID
|
2018-05-22 08:40:06 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisqusShortname is kept here for historic reasons.
|
|
|
|
func (s *SiteInfo) DisqusShortname() string {
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.Config().Services.Disqus.Shortname
|
2016-08-07 08:03:03 -04:00
|
|
|
}
|
|
|
|
|
2014-12-09 13:33:55 -05:00
|
|
|
// SiteSocial is a place to put social details on a site level. These are the
|
|
|
|
// standard keys that themes will expect to have available, but can be
|
|
|
|
// expanded to any others on a per site basis
|
|
|
|
// github
|
|
|
|
// facebook
|
|
|
|
// facebook_admin
|
|
|
|
// twitter
|
|
|
|
// twitter_domain
|
|
|
|
// pinterest
|
|
|
|
// instagram
|
|
|
|
// youtube
|
|
|
|
// linkedin
|
|
|
|
type SiteSocial map[string]string
|
|
|
|
|
2017-02-19 17:53:48 -05:00
|
|
|
// Param is a convenience method to do lookups in SiteInfo's Params map.
|
2016-10-17 13:30:21 -04:00
|
|
|
//
|
|
|
|
// This method is also implemented on Page and Node.
|
|
|
|
func (s *SiteInfo) Param(key interface{}) (interface{}, error) {
|
|
|
|
keyStr, err := cast.ToStringE(key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
keyStr = strings.ToLower(keyStr)
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.Params()[keyStr], nil
|
2016-10-17 13:30:21 -04:00
|
|
|
}
|
|
|
|
|
2016-08-07 08:03:03 -04:00
|
|
|
func (s *SiteInfo) IsMultiLingual() bool {
|
|
|
|
return len(s.Languages) > 1
|
|
|
|
}
|
|
|
|
|
2018-03-30 14:15:22 -04:00
|
|
|
func (s *SiteInfo) IsServer() bool {
|
|
|
|
return s.owner.running
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
type siteRefLinker struct {
|
|
|
|
s *Site
|
|
|
|
|
|
|
|
errorLogger *log.Logger
|
|
|
|
notFoundURL string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newSiteRefLinker(cfg config.Provider, s *Site) (siteRefLinker, error) {
|
|
|
|
logger := s.Log.ERROR
|
|
|
|
|
|
|
|
notFoundURL := cfg.GetString("refLinksNotFoundURL")
|
|
|
|
errLevel := cfg.GetString("refLinksErrorLevel")
|
|
|
|
if strings.EqualFold(errLevel, "warning") {
|
|
|
|
logger = s.Log.WARN
|
|
|
|
}
|
|
|
|
return siteRefLinker{s: s, errorLogger: logger, notFoundURL: notFoundURL}, nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s siteRefLinker) logNotFound(ref, what string, p page.Page, position text.Position) {
|
2018-11-01 06:28:30 -04:00
|
|
|
if position.IsValid() {
|
|
|
|
s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q: %s: %s", s.s.Lang(), ref, position.String(), what)
|
|
|
|
} else if p == nil {
|
2018-08-24 03:23:01 -04:00
|
|
|
s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q: %s", s.s.Lang(), ref, what)
|
2018-07-18 13:58:39 -04:00
|
|
|
} else {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.errorLogger.Printf("[%s] REF_NOT_FOUND: Ref %q from page %q: %s", s.s.Lang(), ref, p.Path(), what)
|
2018-07-18 13:58:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 06:28:30 -04:00
|
|
|
func (s *siteRefLinker) refLink(ref string, source interface{}, 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
|
|
|
|
target, err = s.s.getPageNew(p, refURL.Path)
|
2018-11-01 06:28:30 -04:00
|
|
|
var pos text.Position
|
|
|
|
if err != nil || target == nil {
|
|
|
|
if p, ok := source.(text.Positioner); ok {
|
|
|
|
pos = p.Position()
|
|
|
|
}
|
|
|
|
}
|
2018-05-29 21:35:27 -04:00
|
|
|
|
|
|
|
if err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.logNotFound(refURL.Path, err.Error(), p, pos)
|
2018-07-19 11:17:35 -04:00
|
|
|
return s.notFoundURL, nil
|
2018-05-29 21:35:27 -04:00
|
|
|
}
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
|
|
|
|
if target == nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.logNotFound(refURL.Path, "page not found", p, pos)
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.notFoundURL, nil
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
}
|
|
|
|
|
2017-04-04 12:14:41 -04:00
|
|
|
var permalinker Permalinker = target
|
|
|
|
|
|
|
|
if outputFormat != "" {
|
|
|
|
o := target.OutputFormats().Get(outputFormat)
|
|
|
|
|
|
|
|
if o == nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.logNotFound(refURL.Path, fmt.Sprintf("output format %q", outputFormat), p, pos)
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.notFoundURL, nil
|
2017-04-04 12:14:41 -04:00
|
|
|
}
|
|
|
|
permalinker = o
|
|
|
|
}
|
|
|
|
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
if relative {
|
2017-04-04 12:14:41 -04:00
|
|
|
link = permalinker.RelPermalink()
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
} else {
|
2017-04-04 12:14:41 -04:00
|
|
|
link = permalinker.Permalink()
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 13:34:57 -04:00
|
|
|
if refURL.Fragment != "" {
|
2019-08-16 09:55:03 -04:00
|
|
|
_ = target
|
2015-03-11 13:34:57 -04:00
|
|
|
link = link + "#" + refURL.Fragment
|
2019-11-06 03:20:59 -05:00
|
|
|
|
2019-08-16 09:55:03 -04:00
|
|
|
if pctx, ok := target.(pageContext); ok {
|
2019-01-02 06:33:26 -05:00
|
|
|
if refURL.Path != "" {
|
2019-08-16 09:55:03 -04:00
|
|
|
if di, ok := pctx.getContentConverter().(converter.DocumentInfo); ok {
|
|
|
|
link = link + di.AnchorSuffix()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if pctx, ok := p.(pageContext); ok {
|
|
|
|
if di, ok := pctx.getContentConverter().(converter.DocumentInfo); ok {
|
|
|
|
link = link + di.AnchorSuffix()
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2019-08-16 09:55:03 -04:00
|
|
|
|
Provide (relative) reference funcs & shortcodes.
- `.Ref` and `.RelRef` take a reference (the logical filename for a
page, including extension and/or a document fragment ID) and return
a permalink (or relative permalink) to the referenced document.
- If the reference is a page name (such as `about.md`), the page
will be discovered and the permalink will be returned: `/about/`
- If the reference is a page name with a fragment (such as
`about.md#who`), the page will be discovered and used to add the
`page.UniqueID()` to the resulting fragment and permalink:
`/about/#who:deadbeef`.
- If the reference is a fragment and `.*Ref` has been called from
a `Node` or `SiteInfo`, it will be returned as is: `#who`.
- If the reference is a fragment and `.*Ref` has been called from
a `Page`, it will be returned with the page’s unique ID:
`#who:deadbeef`.
- `.*Ref` can be called from either `Node`, `SiteInfo` (e.g.,
`Node.Site`), `Page` objects, or `ShortcodeWithPage` objects in
templates.
- `.*Ref` cannot be used in content, so two shortcodes have been
created to provide the functionality to content: `ref` and `relref`.
These are intended to be used within markup, like `[Who]({{% ref
about.md#who %}})` or `<a href="{{% ref about.md#who %}}">Who</a>`.
- There are also `ref` and `relref` template functions (used to create
the shortcodes) that expect a `Page` or `Node` object and the
reference string (e.g., `{{ relref . "about.md" }}` or `{{
"about.md" | ref . }}`). It actually looks for `.*Ref` as defined on
`Node` or `Page` objects.
- Shortcode handling had to use a *differently unique* wrapper in
`createShortcodePlaceholder` because of the way that the `ref` and
`relref` are intended to be used in content.
2014-11-24 01:15:34 -05:00
|
|
|
return link, nil
|
|
|
|
}
|
|
|
|
|
2016-01-15 18:28:48 -05:00
|
|
|
// Ref will give an absolute URL to ref in the given Page.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) Ref(ref string, page page.Page, options ...string) (string, error) {
|
|
|
|
// Remove in Hugo 0.54
|
|
|
|
helpers.Deprecated("Site", ".Ref", "Use .Site.GetPage", true)
|
2017-04-04 12:14:41 -04:00
|
|
|
outputFormat := ""
|
|
|
|
if len(options) > 0 {
|
|
|
|
outputFormat = options[0]
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.s.refLink(ref, page, false, outputFormat)
|
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
|
|
|
}
|
|
|
|
|
2016-01-15 18:28:48 -05:00
|
|
|
// RelRef will give an relative URL to ref in the given Page.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) RelRef(ref string, page page.Page, options ...string) (string, error) {
|
|
|
|
// Remove in Hugo 0.54
|
|
|
|
helpers.Deprecated("Site", ".RelRef", "Use .Site.GetPage", true)
|
2017-04-04 12:14:41 -04:00
|
|
|
outputFormat := ""
|
|
|
|
if len(options) > 0 {
|
|
|
|
outputFormat = options[0]
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
return s.s.refLink(ref, page, true, outputFormat)
|
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
|
|
|
}
|
|
|
|
|
2016-04-07 14:03:03 -04:00
|
|
|
func (s *Site) running() bool {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.h != nil && s.h.running
|
2013-10-25 18:03:14 -04:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:58:39 -04:00
|
|
|
func (s *Site) multilingual() *Multilingual {
|
2019-01-02 06:33:26 -05:00
|
|
|
return s.h.multilingual
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2016-08-12 18:33:17 -04:00
|
|
|
type whatChanged struct {
|
|
|
|
source bool
|
|
|
|
other bool
|
2018-01-28 05:46:48 -05:00
|
|
|
files map[string]bool
|
2016-08-12 18:33:17 -04:00
|
|
|
}
|
|
|
|
|
2017-04-04 12:05:19 -04:00
|
|
|
// RegisterMediaTypes will register the Site's media types in the mime
|
|
|
|
// package, so it will behave correctly with Hugo's built-in server.
|
|
|
|
func (s *Site) RegisterMediaTypes() {
|
|
|
|
for _, mt := range s.mediaTypesConfig {
|
2018-07-10 05:55:22 -04:00
|
|
|
for _, suffix := range mt.Suffixes {
|
|
|
|
_ = mime.AddExtensionType(mt.Delimiter+suffix, mt.Type()+"; charset=utf-8")
|
|
|
|
}
|
2017-04-04 12:05:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
func (s *Site) filterFileEvents(events []fsnotify.Event) []fsnotify.Event {
|
|
|
|
var filtered []fsnotify.Event
|
|
|
|
seen := make(map[fsnotify.Event]bool)
|
|
|
|
|
|
|
|
for _, ev := range events {
|
|
|
|
// Avoid processing the same event twice.
|
|
|
|
if seen[ev] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seen[ev] = true
|
|
|
|
|
|
|
|
if s.SourceSpec.IgnoreFile(ev.Name) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Throw away any directories
|
|
|
|
isRegular, err := s.SourceSpec.IsRegularSourceFile(ev.Name)
|
|
|
|
if err != nil && os.IsNotExist(err) && (ev.Op&fsnotify.Remove == fsnotify.Remove || ev.Op&fsnotify.Rename == fsnotify.Rename) {
|
|
|
|
// Force keep of event
|
|
|
|
isRegular = true
|
|
|
|
}
|
|
|
|
if !isRegular {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
// Remove the superflous events to mage the update logic simpler.
|
|
|
|
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.
|
2016-07-28 03:30:58 -04:00
|
|
|
// It returns whetever 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)
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
s.Log.DEBUG.Printf("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
|
|
|
|
tmplChanged = []fsnotify.Event{}
|
|
|
|
dataChanged = []fsnotify.Event{}
|
|
|
|
i18nChanged = []fsnotify.Event{}
|
|
|
|
shortcodesChanged = make(map[string]bool)
|
2018-01-28 05:46:48 -05:00
|
|
|
sourceFilesChanged = make(map[string]bool)
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
|
|
|
|
// prevent spamming the log on changes
|
|
|
|
logger = helpers.NewDistinctFeedbackLogger()
|
|
|
|
)
|
2016-01-28 09:31:25 -05:00
|
|
|
|
2019-08-13 06:35:04 -04:00
|
|
|
var cachePartitions []string
|
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 {
|
|
|
|
if assetsFilename := s.BaseFs.Assets.MakePathRelative(ev.Name); assetsFilename != "" {
|
|
|
|
cachePartitions = append(cachePartitions, resources.ResourceKeyPartitions(assetsFilename)...)
|
|
|
|
}
|
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-07-10 13:37:27 -04:00
|
|
|
if s.isContentDirEvent(ev) {
|
2017-06-08 14:00:05 -04:00
|
|
|
logger.Println("Source changed", ev)
|
2016-01-11 12:06:52 -05:00
|
|
|
sourceChanged = append(sourceChanged, ev)
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
2016-09-11 13:47:12 -04:00
|
|
|
if s.isLayoutDirEvent(ev) {
|
2017-06-08 14:00:05 -04:00
|
|
|
logger.Println("Template changed", ev)
|
2016-01-11 12:06:52 -05:00
|
|
|
tmplChanged = append(tmplChanged, ev)
|
2017-03-10 14:54:50 -05:00
|
|
|
|
|
|
|
if strings.Contains(ev.Name, "shortcodes") {
|
|
|
|
shortcode := filepath.Base(ev.Name)
|
|
|
|
shortcode = strings.TrimSuffix(shortcode, filepath.Ext(shortcode))
|
|
|
|
shortcodesChanged[shortcode] = true
|
|
|
|
}
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
2016-07-10 13:37:27 -04:00
|
|
|
if s.isDataDirEvent(ev) {
|
2017-06-08 14:00:05 -04:00
|
|
|
logger.Println("Data changed", ev)
|
2016-01-28 09:31:25 -05:00
|
|
|
dataChanged = append(dataChanged, ev)
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
2016-09-11 13:47:12 -04:00
|
|
|
if s.isI18nEvent(ev) {
|
2017-06-08 14:00:05 -04:00
|
|
|
logger.Println("i18n changed", ev)
|
2016-07-28 03:30:58 -04:00
|
|
|
i18nChanged = append(dataChanged, ev)
|
|
|
|
}
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
changed := &whatChanged{
|
|
|
|
source: len(sourceChanged) > 0 || len(shortcodesChanged) > 0,
|
|
|
|
other: len(tmplChanged) > 0 || len(i18nChanged) > 0 || len(dataChanged) > 0,
|
|
|
|
files: sourceFilesChanged,
|
|
|
|
}
|
|
|
|
|
|
|
|
config.whatChanged = changed
|
|
|
|
|
|
|
|
if err := init(config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
// These in memory resource caches will be rebuilt on demand.
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, s := range s.h.Sites {
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
s.ResourceSpec.ResourceCache.DeletePartitions(cachePartitions...)
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
if len(tmplChanged) > 0 || len(i18nChanged) > 0 {
|
2019-01-02 06:33:26 -05:00
|
|
|
sites := s.h.Sites
|
2017-01-10 04:55:03 -05:00
|
|
|
first := sites[0]
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
s.h.init.Reset()
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
// TOD(bep) globals clean
|
2017-02-04 22:20:06 -05:00
|
|
|
if err := first.Deps.LoadResources(); err != nil {
|
2019-08-03 11:27:40 -04:00
|
|
|
return err
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := 1; i < len(sites); i++ {
|
|
|
|
site := sites[i]
|
|
|
|
var err error
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
depsCfg := deps.DepsCfg{
|
2019-01-02 06:33:26 -05:00
|
|
|
Language: site.language,
|
2018-08-05 05:13:49 -04:00
|
|
|
MediaTypes: site.mediaTypesConfig,
|
|
|
|
OutputFormats: site.outputFormatsConfig,
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
}
|
2018-11-26 04:11:22 -05:00
|
|
|
site.Deps, err = first.Deps.ForLanguage(depsCfg, func(d *deps.Deps) error {
|
|
|
|
d.Site = &site.Info
|
|
|
|
return nil
|
|
|
|
})
|
2017-01-10 04:55:03 -05:00
|
|
|
if err != nil {
|
2019-08-03 11:27:40 -04:00
|
|
|
return err
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(dataChanged) > 0 {
|
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
|
|
|
|
2017-03-27 19:18:15 -04:00
|
|
|
for shortcode := range shortcodesChanged {
|
2017-03-10 14:54:50 -05:00
|
|
|
// There are certain scenarios that, when a shortcode changes,
|
|
|
|
// it isn't sufficient to just rerender the already parsed shortcode.
|
|
|
|
// One example is if the user adds a new shortcode to the content file first,
|
|
|
|
// and then creates the shortcode on the file system.
|
|
|
|
// To handle these scenarios, we must do a full reprocessing of the
|
|
|
|
// pages that keeps a reference to the changed shortcode.
|
: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
|
|
|
pagesWithShortcode := h.findPagesByShortcode(shortcode)
|
2017-03-10 14:54:50 -05:00
|
|
|
for _, p := range pagesWithShortcode {
|
2019-01-02 06:33:26 -05:00
|
|
|
contentFilesChanged = append(contentFilesChanged, p.File().Filename())
|
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
|
|
|
|
: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 err := s.readAndProcessContent(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
|
2016-05-14 00:35:16 -04:00
|
|
|
|
2015-12-22 00:10:01 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) process(config BuildCfg) (err error) {
|
|
|
|
if err = s.initialize(); err != nil {
|
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
|
|
|
err = errors.Wrap(err, "initialize")
|
2019-01-02 06:33:26 -05:00
|
|
|
return
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
}
|
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 err = s.readAndProcessContent(); err != nil {
|
|
|
|
err = errors.Wrap(err, "readAndProcessContent")
|
|
|
|
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) {
|
2017-05-05 03:24:37 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err := page.Clear(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-05 03:24:37 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if ctx.outIdx == 0 {
|
2017-06-20 04:30:40 -04:00
|
|
|
// Note that even if disableAliases is set, the aliases themselves are
|
|
|
|
// preserved on page. The motivation with this is to be able to generate
|
|
|
|
// 301 redirects in a .htacess file and similar using a custom output format.
|
|
|
|
if !s.Cfg.GetBool("disableAliases") {
|
|
|
|
// Aliases must be rendered before pages.
|
|
|
|
// Some sites, Hugo docs included, have faulty alias definitions that point
|
|
|
|
// to itself or another real page. These will be overwritten in the next
|
|
|
|
// step.
|
|
|
|
if err = s.renderAliases(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2017-05-05 03:24:37 -04:00
|
|
|
}
|
2017-02-18 04:02:12 -05: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
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err = s.renderRobotsTXT(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2016-11-08 17:34:52 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err = s.render404(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2014-05-06 06:50:23 -04:00
|
|
|
}
|
2015-12-08 16:13:09 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if !ctx.renderSingletonPages() {
|
2015-12-08 16:13:09 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err = s.renderMainLanguageRedirect(); err != nil {
|
2016-11-08 17:34:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-01-29 17:50:31 -05:00
|
|
|
return
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:20:58 -04:00
|
|
|
func (s *Site) Initialise() (err error) {
|
|
|
|
return s.initialize()
|
|
|
|
}
|
|
|
|
|
2013-09-25 00:24:49 -04:00
|
|
|
func (s *Site) initialize() (err error) {
|
2018-05-04 04:18:45 -04:00
|
|
|
return s.initializeSiteInfo()
|
2013-09-12 19:17:53 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 10:11:03 -04:00
|
|
|
// HomeAbsURL is a convenience method giving the absolute URL to the home page.
|
2016-08-04 16:12:19 -04:00
|
|
|
func (s *SiteInfo) HomeAbsURL() string {
|
2016-08-07 16:01:55 -04:00
|
|
|
base := ""
|
2016-08-07 08:03:03 -04:00
|
|
|
if s.IsMultiLingual() {
|
2018-11-26 04:11:22 -05:00
|
|
|
base = s.Language().Lang
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
2017-01-10 04:55:03 -05:00
|
|
|
return s.owner.AbsURL(base, false)
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// SitemapAbsURL is a convenience method giving the absolute URL to the sitemap.
|
|
|
|
func (s *SiteInfo) SitemapAbsURL() string {
|
2016-09-30 10:24:09 -04:00
|
|
|
p := s.HomeAbsURL()
|
|
|
|
if !strings.HasSuffix(p, "/") {
|
|
|
|
p += "/"
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
p += s.s.siteCfg.sitemap.Filename
|
2016-09-30 10:24:09 -04:00
|
|
|
return p
|
2016-08-04 16:12:19 -04:00
|
|
|
}
|
|
|
|
|
2018-05-04 04:18:45 -04:00
|
|
|
func (s *Site) initializeSiteInfo() error {
|
2016-07-24 07:58:27 -04:00
|
|
|
var (
|
2019-01-02 06:33:26 -05:00
|
|
|
lang = s.language
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
languages langs.Languages
|
2016-07-24 07:58:27 -04:00
|
|
|
)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if s.h != nil && s.h.multilingual != nil {
|
|
|
|
languages = s.h.multilingual.Languages
|
2016-07-24 07:58:27 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
permalinks := s.Cfg.GetStringMapString("permalinks")
|
2014-04-05 01:26:43 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
defaultContentInSubDir := s.Cfg.GetBool("defaultContentLanguageInSubdir")
|
|
|
|
defaultContentLanguage := s.Cfg.GetString("defaultContentLanguage")
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2016-05-14 00:35:16 -04:00
|
|
|
languagePrefix := ""
|
2016-08-08 07:55:18 -04:00
|
|
|
if s.multilingualEnabled() && (defaultContentInSubDir || lang.Lang != defaultContentLanguage) {
|
2016-07-24 07:58:27 -04:00
|
|
|
languagePrefix = "/" + lang.Lang
|
2016-05-14 00:35:16 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
var uglyURLs = func(p page.Page) bool {
|
2018-01-11 11:46:43 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
v := s.Cfg.Get("uglyURLs")
|
|
|
|
if v != nil {
|
2018-01-28 11:03:10 -05:00
|
|
|
switch vv := v.(type) {
|
|
|
|
case bool:
|
2019-01-02 06:33:26 -05:00
|
|
|
uglyURLs = func(p page.Page) bool {
|
2018-01-11 11:46:43 -05:00
|
|
|
return vv
|
|
|
|
}
|
2018-01-28 11:03:10 -05:00
|
|
|
case string:
|
|
|
|
// Is what be get from CLI (--uglyURLs)
|
|
|
|
vvv := cast.ToBool(vv)
|
2019-01-02 06:33:26 -05:00
|
|
|
uglyURLs = func(p page.Page) bool {
|
2018-01-28 11:03:10 -05:00
|
|
|
return vvv
|
|
|
|
}
|
|
|
|
default:
|
2018-01-11 11:46:43 -05:00
|
|
|
m := cast.ToStringMapBool(v)
|
2019-01-02 06:33:26 -05:00
|
|
|
uglyURLs = func(p page.Page) bool {
|
2018-01-11 11:46:43 -05:00
|
|
|
return m[p.Section()]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-24 12:18:47 -04:00
|
|
|
s.Info = SiteInfo{
|
2019-01-02 06:33:26 -05:00
|
|
|
title: lang.GetString("title"),
|
2016-09-18 13:10:11 -04:00
|
|
|
Author: lang.GetStringMap("author"),
|
2016-08-08 07:55:18 -04:00
|
|
|
Social: lang.GetStringMapString("social"),
|
2016-10-24 14:56:00 -04:00
|
|
|
LanguageCode: lang.GetString("languageCode"),
|
2016-08-08 07:55:18 -04:00
|
|
|
Copyright: lang.GetString("copyright"),
|
2018-11-26 04:11:22 -05:00
|
|
|
language: lang,
|
2016-08-08 07:55:18 -04:00
|
|
|
LanguagePrefix: languagePrefix,
|
|
|
|
Languages: languages,
|
|
|
|
defaultContentLanguageInSubdir: defaultContentInSubDir,
|
2016-11-23 16:06:15 -05:00
|
|
|
sectionPagesMenu: lang.GetString("sectionPagesMenu"),
|
2017-02-04 22:20:06 -05:00
|
|
|
BuildDrafts: s.Cfg.GetBool("buildDrafts"),
|
|
|
|
canonifyURLs: s.Cfg.GetBool("canonifyURLs"),
|
2017-02-20 03:52:06 -05:00
|
|
|
relativeURLs: s.Cfg.GetBool("relativeURLs"),
|
2018-01-11 11:46:43 -05:00
|
|
|
uglyURLs: uglyURLs,
|
2019-01-02 06:33:26 -05:00
|
|
|
permalinks: permalinks,
|
|
|
|
owner: s.h,
|
2017-01-10 04:55:03 -05:00
|
|
|
s: s,
|
2018-11-15 03:28:02 -05:00
|
|
|
hugoInfo: hugo.NewInfo(s.Cfg.GetString("environment")),
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
2016-10-24 07:45:30 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
rssOutputFormat, found := s.outputFormats[page.KindHome].GetByName(output.RSSFormat.Name)
|
2017-05-17 12:57:44 -04:00
|
|
|
|
|
|
|
if found {
|
|
|
|
s.Info.RSSLink = s.permalink(rssOutputFormat.BaseFilename())
|
|
|
|
}
|
2018-05-04 04:18:45 -04:00
|
|
|
|
|
|
|
return nil
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2016-09-11 13:47:12 -04:00
|
|
|
func (s *Site) isI18nEvent(e fsnotify.Event) bool {
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return s.BaseFs.SourceFilesystems.IsI18n(e.Name)
|
2016-05-14 00:35:16 -04:00
|
|
|
}
|
|
|
|
|
2016-07-10 13:37:27 -04:00
|
|
|
func (s *Site) isDataDirEvent(e fsnotify.Event) bool {
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return s.BaseFs.SourceFilesystems.IsData(e.Name)
|
2016-09-11 13:47:12 -04:00
|
|
|
}
|
|
|
|
|
2016-07-10 13:37:27 -04:00
|
|
|
func (s *Site) isLayoutDirEvent(e fsnotify.Event) bool {
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return s.BaseFs.SourceFilesystems.IsLayout(e.Name)
|
2016-09-11 13:47:12 -04:00
|
|
|
}
|
|
|
|
|
2016-07-10 13:37:27 -04:00
|
|
|
func (s *Site) isContentDirEvent(e fsnotify.Event) bool {
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return s.BaseFs.IsContent(e.Name)
|
2013-07-04 11:32:55 -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) readAndProcessContent(filenames ...string) error {
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
sourceSpec := source.NewSourceSpec(s.PathSpec, s.BaseFs.Content.Fs)
|
2018-03-21 12:21:46 -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
|
|
|
proc := newPagesProcessor(s.h, sourceSpec, len(filenames) > 0)
|
2016-01-08 18:37:37 -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
|
|
|
c := newPagesCollector(sourceSpec, s.Log, s.h.ContentChanges, proc, filenames...)
|
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
|
|
|
return c.Collect()
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) getMenusFromConfig() navigation.Menus {
|
2014-04-24 18:11:08 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
ret := navigation.Menus{}
|
2014-04-24 18:11:08 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if menus := s.language.GetStringMap("menus"); menus != nil {
|
2014-04-24 18:11:08 -04:00
|
|
|
for name, menu := range menus {
|
|
|
|
m, err := cast.ToSliceE(menu)
|
|
|
|
if err != nil {
|
2017-01-10 04:55:03 -05:00
|
|
|
s.Log.ERROR.Printf("unable to process menus in site config\n")
|
|
|
|
s.Log.ERROR.Println(err)
|
2014-04-24 18:11:08 -04:00
|
|
|
} else {
|
|
|
|
for _, entry := range m {
|
2017-01-10 04:55:03 -05:00
|
|
|
s.Log.DEBUG.Printf("found menu: %q, in site config\n", name)
|
2014-04-24 18:11:08 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
menuEntry := navigation.MenuEntry{Menu: name}
|
2014-04-24 18:11:08 -04:00
|
|
|
ime, err := cast.ToStringMapE(entry)
|
|
|
|
if err != nil {
|
2017-01-10 04:55:03 -05:00
|
|
|
s.Log.ERROR.Printf("unable to process menus in site config\n")
|
|
|
|
s.Log.ERROR.Println(err)
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
menuEntry.MarshallMap(ime)
|
2019-04-19 03:18:12 -04:00
|
|
|
// TODO(bep) clean up all of this
|
|
|
|
menuEntry.ConfiguredURL = s.Info.createNodeMenuEntryURL(menuEntry.ConfiguredURL)
|
2014-12-12 14:28:28 -05:00
|
|
|
|
2014-04-24 18:11:08 -04:00
|
|
|
if ret[name] == nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
ret[name] = navigation.Menu{}
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
ret[name] = ret[name].Add(&menuEntry)
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2015-05-09 14:54:11 -04:00
|
|
|
func (s *SiteInfo) createNodeMenuEntryURL(in string) string {
|
|
|
|
|
|
|
|
if !strings.HasPrefix(in, "/") {
|
|
|
|
return in
|
|
|
|
}
|
|
|
|
// make it match the nodes
|
|
|
|
menuEntryURL := in
|
2017-01-10 04:55:03 -05:00
|
|
|
menuEntryURL = helpers.SanitizeURLKeepTrailingSlash(s.s.PathSpec.URLize(menuEntryURL))
|
2015-05-09 14:54:11 -04:00
|
|
|
if !s.canonifyURLs {
|
2017-04-07 12:33:28 -04:00
|
|
|
menuEntryURL = helpers.AddContextRoot(s.s.PathSpec.BaseURL.String(), menuEntryURL)
|
2015-05-09 14:54:11 -04:00
|
|
|
}
|
|
|
|
return menuEntryURL
|
|
|
|
}
|
|
|
|
|
2014-04-23 02:59:19 -04:00
|
|
|
func (s *Site) assembleMenus() {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.menus = make(navigation.Menus)
|
2014-04-23 02:59:19 -04:00
|
|
|
|
|
|
|
type twoD struct {
|
|
|
|
MenuName, EntryName string
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
flat := map[twoD]*navigation.MenuEntry{}
|
|
|
|
children := map[twoD]navigation.Menu{}
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2017-01-22 06:28:31 -05:00
|
|
|
// add menu entries from config to flat hash
|
2014-04-24 18:11:08 -04:00
|
|
|
menuConfig := s.getMenusFromConfig()
|
|
|
|
for name, menu := range menuConfig {
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, me := range menu {
|
2014-05-14 18:01:13 -04:00
|
|
|
flat[twoD{name, me.KeyName()}] = me
|
2014-04-24 18:11:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 16:06:15 -05:00
|
|
|
sectionPagesMenu := s.Info.sectionPagesMenu
|
2017-01-22 06:28:31 -05:00
|
|
|
|
|
|
|
if sectionPagesMenu != "" {
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, p := range s.workAllPages {
|
|
|
|
if p.Kind() == page.KindSection {
|
2017-04-09 04:33:04 -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.
|
2017-02-20 03:33:35 -05:00
|
|
|
id := p.Section()
|
|
|
|
if _, ok := flat[twoD{sectionPagesMenu, id}]; ok {
|
2017-01-22 06:28:31 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
me := navigation.MenuEntry{Identifier: id,
|
2017-01-22 06:28:31 -05:00
|
|
|
Name: p.LinkTitle(),
|
2019-01-02 06:33:26 -05:00
|
|
|
Weight: p.Weight(),
|
2019-04-19 03:18:12 -04:00
|
|
|
Page: p}
|
2017-01-22 06:28:31 -05:00
|
|
|
flat[twoD{sectionPagesMenu, me.KeyName()}] = &me
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-06 12:11:06 -05:00
|
|
|
|
2017-01-22 06:28:31 -05:00
|
|
|
// Add menu entries provided by pages
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, p := range s.workAllPages {
|
|
|
|
for name, me := range p.pageMenus.menus() {
|
2014-05-14 18:01:13 -04:00
|
|
|
if _, ok := flat[twoD{name, me.KeyName()}]; ok {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.SendError(p.wrapError(errors.Errorf("duplicate menu entry with identifier %q in menu %q", me.KeyName(), name)))
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Children Menus First
|
|
|
|
for _, e := range flat {
|
|
|
|
if e.Parent != "" {
|
2019-01-02 06:33:26 -05:00
|
|
|
children[twoD{e.Menu, e.Parent}] = children[twoD{e.Menu, e.Parent}].Add(e)
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placing Children in Parents (in flat)
|
|
|
|
for p, childmenu := range children {
|
|
|
|
_, ok := flat[twoD{p.MenuName, p.EntryName}]
|
|
|
|
if !ok {
|
2015-03-18 01:16:54 -04:00
|
|
|
// if parent does not exist, create one without a URL
|
2019-04-19 03:18:12 -04:00
|
|
|
flat[twoD{p.MenuName, p.EntryName}] = &navigation.MenuEntry{Name: p.EntryName}
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
|
|
|
flat[twoD{p.MenuName, p.EntryName}].Children = childmenu
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assembling Top Level of Tree
|
|
|
|
for menu, e := range flat {
|
|
|
|
if e.Parent == "" {
|
2019-01-02 06:33:26 -05:00
|
|
|
_, ok := s.menus[menu.MenuName]
|
2014-04-23 02:59:19 -04:00
|
|
|
if !ok {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.menus[menu.MenuName] = navigation.Menu{}
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
s.menus[menu.MenuName] = s.menus[menu.MenuName].Add(e)
|
2014-04-23 02:59:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// get any lanaguagecode to prefix the target file path with.
|
|
|
|
func (s *Site) getLanguageTargetPathLang(alwaysInSubDir bool) string {
|
|
|
|
if s.h.IsMultihost() {
|
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.getLanguagePermalinkLang(alwaysInSubDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// get any lanaguagecode to prefix the relative permalink with.
|
|
|
|
func (s *Site) getLanguagePermalinkLang(alwaysInSubDir bool) string {
|
|
|
|
|
|
|
|
if !s.Info.IsMultiLingual() || s.h.IsMultihost() {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if alwaysInSubDir {
|
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
|
|
|
isDefault := s.Language().Lang == s.multilingual().DefaultLang.Lang
|
|
|
|
|
|
|
|
if !isDefault || s.Info.defaultContentLanguageInSubdir {
|
|
|
|
return s.Language().Lang
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
func (s *Site) getTaxonomyKey(key string) string {
|
2019-01-02 06:33:26 -05:00
|
|
|
if s.PathSpec.DisablePathToLower {
|
|
|
|
return s.PathSpec.MakePath(key)
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return strings.ToLower(s.PathSpec.MakePath(key))
|
2017-01-10 04:55:03 -05:00
|
|
|
}
|
2017-02-18 04:02:12 -05:00
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
// Prepare site for a new full build.
|
2019-08-03 11:27:40 -04:00
|
|
|
func (s *Site) resetBuildState(sourceChanged bool) {
|
2019-01-02 06:33:26 -05:00
|
|
|
s.relatedDocsHandler = s.relatedDocsHandler.Clone()
|
|
|
|
s.init.Reset()
|
2016-03-06 10:33:32 -05:00
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
if sourceChanged {
|
|
|
|
s.PageCollections = newPageCollectionsFromPages(s.rawAllPages)
|
|
|
|
for _, p := range s.rawAllPages {
|
|
|
|
p.pagePages = &pagePages{}
|
|
|
|
p.parent = nil
|
|
|
|
p.Scratcher = maps.NewScratcher()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s.pagesMap.withEveryPage(func(p *pageState) {
|
|
|
|
p.Scratcher = maps.NewScratcher()
|
|
|
|
})
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
2018-10-03 08:58:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Site) errorCollator(results <-chan error, errs chan<- error) {
|
|
|
|
var errors []error
|
|
|
|
for e := range results {
|
|
|
|
errors = append(errors, e)
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
errs <- s.h.pickOneAndLogTheRest(errors)
|
2018-10-03 08:58:09 -04:00
|
|
|
|
|
|
|
close(errs)
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
|
|
|
|
2018-05-29 21:35:27 -04:00
|
|
|
// GetPage looks up a page of a given type for the given ref.
|
2018-07-17 05:18:29 -04:00
|
|
|
// In Hugo <= 0.44 you had to add Page Kind (section, home) etc. as the first
|
|
|
|
// argument and then either a unix styled path (with or without a leading slash))
|
|
|
|
// or path elements separated.
|
|
|
|
// When we now remove the Kind from this API, we need to make the transition as painless
|
|
|
|
// as possible for existing sites. Most sites will use {{ .Site.GetPage "section" "my/section" }},
|
|
|
|
// i.e. 2 arguments, so we test for that.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *SiteInfo) GetPage(ref ...string) (page.Page, error) {
|
|
|
|
p, err := s.s.getPageOldVersion(ref...)
|
2016-11-12 11:30:21 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if p == nil {
|
|
|
|
// The nil struct has meaning in some situations, mostly to avoid breaking
|
|
|
|
// existing sites doing $nilpage.IsDescendant($p), which will always return
|
|
|
|
// false.
|
|
|
|
p = page.NilPage
|
2017-03-23 15:05:10 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
return p, err
|
2017-03-23 15:05:10 -04:00
|
|
|
}
|
|
|
|
|
2017-03-09 13:19:29 -05:00
|
|
|
func (s *Site) permalink(link string) string {
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
return s.PathSpec.PermalinkForBaseURL(link, s.PathSpec.BaseURL.String())
|
2017-03-23 15:05:10 -04:00
|
|
|
|
|
|
|
}
|
2014-10-18 14:25:10 -04:00
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
func (s *Site) renderAndWriteXML(statCounter *uint64, name string, targetPath string, d interface{}, layouts ...string) error {
|
|
|
|
s.Log.DEBUG.Printf("Render XML for %q to %q", name, targetPath)
|
2015-01-30 14:51:06 -05:00
|
|
|
renderBuffer := bp.GetBuffer()
|
|
|
|
defer bp.PutBuffer(renderBuffer)
|
2014-12-18 14:59:39 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err := s.renderForLayouts(name, "", d, renderBuffer, layouts...); 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
|
|
|
var path string
|
2017-02-20 03:52:06 -05:00
|
|
|
if s.Info.relativeURLs {
|
2018-08-05 05:13:49 -04:00
|
|
|
path = helpers.GetDottedRelativePath(targetPath)
|
2015-05-15 18:11:39 -04:00
|
|
|
} else {
|
2017-11-12 04:03:56 -05:00
|
|
|
s := s.PathSpec.BaseURL.String()
|
2015-05-15 18:11:39 -04:00
|
|
|
if !strings.HasSuffix(s, "/") {
|
|
|
|
s += "/"
|
|
|
|
}
|
2018-08-05 05:13:49 -04:00
|
|
|
path = s
|
2015-05-15 18:11:39 -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,
|
|
|
|
AbsURLPath: path,
|
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)
|
2015-01-30 14:51:06 -05:00
|
|
|
|
2014-11-04 00:39:37 -05:00
|
|
|
}
|
2013-10-01 22:58:15 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath string, p *pageState, layouts ...string) error {
|
2015-01-30 15:05:05 -05:00
|
|
|
renderBuffer := bp.GetBuffer()
|
|
|
|
defer bp.PutBuffer(renderBuffer)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
of := p.outputFormat()
|
2018-10-03 08:58:09 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err := s.renderForLayouts(p.Kind(), of.Name, p, renderBuffer, layouts...); err != nil {
|
2018-10-03 08:58:09 -04:00
|
|
|
return err
|
2016-07-25 16:22:09 -04:00
|
|
|
}
|
|
|
|
|
2017-04-23 16:03:25 -04:00
|
|
|
if renderBuffer.Len() == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
isHTML := of.IsHTML
|
|
|
|
isRSS := of.Name == "RSS"
|
2014-01-29 17:50:31 -05:00
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
var path string
|
2014-01-29 17:50:31 -05:00
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
if s.Info.relativeURLs {
|
|
|
|
path = helpers.GetDottedRelativePath(targetPath)
|
2019-01-02 06:33:26 -05:00
|
|
|
} else if isRSS || s.Info.canonifyURLs {
|
2018-08-05 05:13:49 -04:00
|
|
|
url := s.PathSpec.BaseURL.String()
|
|
|
|
if !strings.HasSuffix(url, "/") {
|
|
|
|
url += "/"
|
|
|
|
}
|
|
|
|
path = url
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
pd.AbsURLPath = path
|
|
|
|
} else if isHTML {
|
2017-04-07 05:01:36 -04:00
|
|
|
if s.Info.relativeURLs || s.Info.canonifyURLs {
|
2018-08-05 05:13:49 -04:00
|
|
|
pd.AbsURLPath = path
|
2017-04-07 05:01:36 -04:00
|
|
|
}
|
2014-05-16 17:49:27 -04:00
|
|
|
|
2017-04-07 05:01:36 -04:00
|
|
|
if s.running() && s.Cfg.GetBool("watch") && !s.Cfg.GetBool("disableLiveReload") {
|
2018-08-05 05:13:49 -04:00
|
|
|
pd.LiveReloadPort = s.Cfg.GetInt("liveReloadPort")
|
2017-04-07 05:01:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// For performance reasons we only inject the Hugo generator tag on the home page.
|
|
|
|
if p.IsHome() {
|
2018-08-05 05:13:49 -04:00
|
|
|
pd.AddHugoGeneratorTag = !s.Cfg.GetBool("disableHugoGeneratorInject")
|
2015-05-15 18:11:39 -04:00
|
|
|
}
|
|
|
|
|
2017-04-06 11:39:20 -04:00
|
|
|
}
|
2015-01-30 15:05:05 -05:00
|
|
|
|
2018-08-05 05:13:49 -04:00
|
|
|
return s.publisher.Publish(pd)
|
2014-11-04 00:39:37 -05:00
|
|
|
}
|
2014-01-29 17:50:31 -05:00
|
|
|
|
Make WARN the new default log log level
This commit also pulls down the log level for a set of WARN statements to INFO. There should be no ERRORs or WARNINGs in a regular Hugo build. That is the story about the Boy Who Cried Wolf.
Since the WARN log is now more visible, this commit also improves on some of them, most notable the "layout not found", which now would look something like this:
```bash
WARN 2018/11/02 09:02:18 Found no layout for "home", language "en", output format "CSS": create a template below /layouts with one of these filenames: index.en.css.css, home.en.css.css, list.en.css.css, index.css.css, home.css.css, list.css.css, index.en.css, home.en.css, list.en.css, index.css, home.css, list.css, _default/index.en.css.css, _default/home.en.css.css, _default/list.en.css.css, _default/index.css.css, _default/home.css.css, _default/list.css.css, _default/index.en.css, _default/home.en.css, _default/list.en.css, _default/index.css, _default/home.css, _default/list.css
```
Fixes #5203
2018-11-01 17:27:42 -04:00
|
|
|
var infoOnMissingLayout = map[string]bool{
|
|
|
|
// The 404 layout is very much optional in Hugo, but we do look for it.
|
|
|
|
"404": true,
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) renderForLayouts(name, outputFormat string, d interface{}, w io.Writer, layouts ...string) (err error) {
|
|
|
|
templ := s.findFirstTemplate(layouts...)
|
2017-03-27 14:43:49 -04:00
|
|
|
if templ == nil {
|
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
|
|
|
log := s.Log.WARN
|
|
|
|
if infoOnMissingLayout[name] {
|
|
|
|
log = s.Log.INFO
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
errMsg := "You should create a template file which matches Hugo Layouts Lookup Rules for this combination."
|
|
|
|
var args []interface{}
|
|
|
|
msg := "found no layout file for"
|
|
|
|
if outputFormat != "" {
|
|
|
|
msg += " %q"
|
|
|
|
args = append(args, outputFormat)
|
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
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
if name != "" {
|
|
|
|
msg += " for %q"
|
|
|
|
args = append(args, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
msg += ": " + errMsg
|
|
|
|
|
|
|
|
log.Printf(msg, args...)
|
|
|
|
|
2018-10-03 08:58:09 -04:00
|
|
|
return nil
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
|
|
|
|
2017-07-14 04:26:51 -04:00
|
|
|
if err = templ.Execute(w, d); err != nil {
|
2018-10-03 08:58:09 -04:00
|
|
|
return _errors.Wrapf(err, "render of %q failed", name)
|
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
|
|
|
}
|
|
|
|
|
2017-03-27 14:43:49 -04:00
|
|
|
func (s *Site) findFirstTemplate(layouts ...string) tpl.Template {
|
2014-04-08 23:15:57 -04:00
|
|
|
for _, layout := range layouts {
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
if templ, found := s.Tmpl.Lookup(layout); found {
|
2017-03-27 14:43:49 -04:00
|
|
|
return templ
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
|
|
|
}
|
2017-03-27 14:43:49 -04:00
|
|
|
return nil
|
2013-08-27 05:09:50 -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) publish(statCounter *uint64, path string, r io.Reader) (err error) {
|
|
|
|
s.PathSpec.ProcessingStats.Incr(statCounter)
|
|
|
|
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
return helpers.WriteToDisk(filepath.Clean(path), r, s.BaseFs.PublishFs)
|
2017-03-16 04:09:26 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) kindFromFileInfoOrSections(fi *fileInfo, sections []string) string {
|
|
|
|
if fi.TranslationBaseName() == "_index" {
|
|
|
|
if fi.Dir() == "" {
|
|
|
|
return page.KindHome
|
2014-08-29 13:40:21 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
return s.kindFromSections(sections)
|
|
|
|
|
2014-08-29 13:40:21 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return page.KindPage
|
2014-08-29 13:40:21 -04:00
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) kindFromSections(sections []string) string {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
if len(sections) == 0 {
|
|
|
|
return page.KindHome
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2017-03-17 11:35:09 -04:00
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
return s.kindFromSectionPath(path.Join(sections...))
|
|
|
|
|
|
|
|
}
|
2017-03-17 11:35:09 -04:00
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
func (s *Site) kindFromSectionPath(sectionPath string) string {
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, plural := range s.siteCfg.taxonomiesConfig {
|
|
|
|
if plural == sectionPath {
|
|
|
|
return page.KindTaxonomyTerm
|
|
|
|
}
|
2017-03-06 07:18:33 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if strings.HasPrefix(sectionPath, plural) {
|
|
|
|
return page.KindTaxonomy
|
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return page.KindSection
|
|
|
|
}
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) newTaxonomyPage(title string, sections ...string) *pageState {
|
2019-08-09 04:05:22 -04:00
|
|
|
p, err := newPageFromMeta(
|
|
|
|
map[string]interface{}{"title": title},
|
|
|
|
&pageMeta{
|
|
|
|
s: s,
|
|
|
|
kind: page.KindTaxonomy,
|
|
|
|
sections: sections,
|
|
|
|
})
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2016-11-16 15:06:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2016-11-16 15:06:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) newPage(kind string, sections ...string) *pageState {
|
2019-08-09 04:05:22 -04:00
|
|
|
p, err := newPageFromMeta(
|
|
|
|
map[string]interface{}{},
|
|
|
|
&pageMeta{
|
|
|
|
s: s,
|
|
|
|
kind: kind,
|
|
|
|
sections: sections,
|
|
|
|
})
|
2016-11-16 15:06:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2016-11-16 15:06:10 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2016-11-16 15:06:10 -05:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) shouldBuild(p page.Page) bool {
|
|
|
|
return shouldBuild(s.BuildFuture, s.BuildExpired,
|
|
|
|
s.BuildDrafts, p.Draft(), p.PublishDate(), p.ExpiryDate())
|
|
|
|
}
|
|
|
|
|
|
|
|
func shouldBuild(buildFuture bool, buildExpired bool, buildDrafts bool, Draft bool,
|
|
|
|
publishDate time.Time, expiryDate time.Time) bool {
|
|
|
|
if !(buildDrafts || !Draft) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !buildFuture && !publishDate.IsZero() && publishDate.After(time.Now()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !buildExpired && !expiryDate.IsZero() && expiryDate.Before(time.Now()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2016-11-16 15:06:10 -05:00
|
|
|
}
|