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
// Copyright 2018 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
"bytes"
2018-04-19 12:06:40 -04:00
"context"
2014-01-29 17:50:31 -05:00
"errors"
"fmt"
2015-01-25 06:08:02 -05:00
"reflect"
2018-10-21 06:20:21 -04:00
"github.com/gohugoio/hugo/common/maps"
2018-11-01 06:28:30 -04:00
"github.com/gohugoio/hugo/common/urls"
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
"github.com/gohugoio/hugo/media"
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
"github.com/gohugoio/hugo/langs"
2017-08-19 07:16:00 -04:00
"github.com/gohugoio/hugo/related"
2016-11-01 18:04:12 -04:00
"github.com/bep/gitmap"
2017-06-13 12:42:45 -04:00
"github.com/gohugoio/hugo/helpers"
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
"github.com/gohugoio/hugo/hugolib/pagemeta"
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
"github.com/gohugoio/hugo/resource"
2017-06-13 12:42:45 -04:00
"github.com/gohugoio/hugo/output"
2017-06-13 13:07:35 -04:00
"github.com/mitchellh/mapstructure"
2014-11-28 15:16:57 -05:00
2014-12-07 13:48:00 -05:00
"html/template"
"io"
"path"
"path/filepath"
2015-09-03 06:22:20 -04:00
"regexp"
2018-04-23 23:57:33 -04:00
"runtime"
2014-12-07 13:48:00 -05:00
"strings"
2015-01-21 09:28:05 -05:00
"sync"
2014-12-07 13:48:00 -05:00
"time"
2015-09-03 06:22:20 -04:00
"unicode/utf8"
2015-01-25 06:08:02 -05:00
2017-08-17 04:24:17 -04:00
"github.com/gohugoio/hugo/compare"
2017-06-13 12:42:45 -04:00
"github.com/gohugoio/hugo/source"
2017-06-13 13:07:35 -04:00
"github.com/spf13/cast"
2013-07-04 11:32:55 -04:00
)
2015-09-03 06:22:20 -04:00
var (
2017-05-26 03:51:17 -04:00
cjk = regexp . MustCompile ( ` \p { Han}|\p { Hangul}|\p { Hiragana}|\p { Katakana} ` )
// This is all the kinds we can expect to find in .Site.Pages.
allKindsInPages = [ ] string { KindPage , KindHome , KindSection , KindTaxonomy , KindTaxonomyTerm }
allKinds = append ( allKindsInPages , [ ] string { kindRSS , kindSitemap , kindRobotsTXT , kind404 } ... )
2017-08-17 04:24:17 -04:00
// Assert that it implements the Eqer interface.
_ compare . Eqer = ( * Page ) ( nil )
_ compare . Eqer = ( * PageOutput ) ( nil )
2017-08-19 07:16:00 -04:00
// Assert that it implements the interface needed for related searches.
_ related . Document = ( * Page ) ( nil )
2018-11-01 06:28:30 -04:00
// Page supports ref and relref
_ urls . RefLinker = ( * Page ) ( nil )
2015-09-03 06:22:20 -04:00
)
2018-11-01 06:28:30 -04:00
// Wraps a Page.
type pageContainer interface {
page ( ) * Page
}
2016-11-11 03:19:16 -05:00
const (
2016-11-13 06:33:11 -05:00
KindPage = "page"
2016-11-11 03:19:16 -05:00
// The rest are node types; home page, sections etc.
2017-09-25 22:25:33 -04:00
2016-11-13 06:33:11 -05:00
KindHome = "home"
KindSection = "section"
KindTaxonomy = "taxonomy"
KindTaxonomyTerm = "taxonomyTerm"
2016-11-11 03:19:16 -05:00
// Temporary state.
2016-11-13 06:33:11 -05:00
kindUnknown = "unknown"
2016-11-11 03:19:16 -05:00
// The following are (currently) temporary nodes,
// i.e. nodes we create just to render in isolation.
2016-11-15 04:43:49 -05:00
kindRSS = "RSS"
2016-11-13 06:33:11 -05:00
kindSitemap = "sitemap"
kindRobotsTXT = "robotsTXT"
kind404 = "404"
: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
pageResourceType = "page"
2016-11-11 03:19:16 -05:00
)
2013-07-04 11:32:55 -04:00
type Page struct {
2016-11-16 14:32:38 -05:00
* pageInit
2018-04-19 12:06:40 -04:00
* pageContentInit
2016-11-13 05:43:23 -05:00
2016-11-13 06:33:11 -05:00
// Kind is the discriminator that identifies the different page types
// in the different page collections. This can, as an example, be used
// to to filter regular pages, find sections etc.
2016-11-13 05:43:23 -05:00
// Kind will, for the pages available to the templates, be one of:
// page, home, section, taxonomy and taxonomyTerm.
2016-11-13 06:33:11 -05:00
// It is of string type to make it easy to reason about in
// the templates.
Kind string
2016-11-11 03:19:16 -05:00
// Since Hugo 0.18 we got rid of the Node type. So now all pages are ...
// pages (regular pages, home page, sections etc.).
// Sections etc. will have child pages. These were earlier placed in .Data.Pages,
// but can now be more intuitively also be fetched directly from .Pages.
// This collection will be nil for regular pages.
Pages Pages
: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
// Since Hugo 0.32, a Page can have resources such as images and CSS associated
// with itself. The resource will typically be placed relative to the Page,
// but templates should use the links (Permalink and RelPermalink)
// provided by the Resource object.
Resources resource . Resources
2018-01-15 14:40:39 -05:00
// This is the raw front matter metadata that is going to be assigned to
// the Resources above.
resourcesMetadata [ ] map [ string ] interface { }
2016-11-16 11:52:03 -05:00
// translations will contain references to this page in other language
// if available.
translations Pages
2017-11-17 10:28:35 -05:00
// A key that maps to translation(s) of this page. This value is fetched
// from the page front matter.
translationKey string
2016-11-16 11:52:03 -05:00
// Params contains configuration defined in the params section of page frontmatter.
2018-01-15 14:40:39 -05:00
params map [ string ] interface { }
2016-11-13 08:27:10 -05:00
2016-11-16 11:52:03 -05:00
// Content sections
2018-04-19 12:06:40 -04:00
contentv template . HTML
summary template . HTML
2016-11-13 08:27:10 -05:00
TableOfContents template . HTML
2018-10-18 04:21:23 -04:00
2018-04-19 12:06:40 -04:00
// Passed to the shortcodes
pageWithoutContent * PageWithoutContent
2016-11-13 08:27:10 -05:00
2016-11-16 11:52:03 -05:00
Aliases [ ] string
Images [ ] Image
Videos [ ] Video
2018-04-19 12:06:40 -04:00
truncated bool
2016-11-13 08:27:10 -05:00
Draft bool
2016-11-16 11:52:03 -05:00
Status string
2016-11-13 08:27:10 -05:00
2016-11-16 11:52:03 -05:00
// PageMeta contains page stats such as word count etc.
PageMeta
2016-11-13 08:27:10 -05:00
2016-11-16 11:52:03 -05:00
// Markup contains the markup type for the content.
Markup string
2016-11-13 08:27:10 -05:00
extension string
contentType string
2017-03-25 13:28:38 -04:00
Layout string
// For npn-renderable pages (see IsRenderable), the content itself
// is used as template and the template name is stored here.
selfLayout string
2016-11-13 08:27:10 -05:00
2016-11-16 11:52:03 -05:00
linkTitle string
2018-10-18 04:21:23 -04:00
// Content items.
pageContent
2016-12-01 04:21:49 -05:00
2016-11-16 11:52:03 -05:00
// whether the content is in a CJK language.
isCJKLanguage bool
// the content stripped for HTML
2016-11-16 14:32:38 -05:00
plain string // TODO should be []byte
plainWords [ ] string
2016-11-16 11:52:03 -05:00
// rendering configuration
Reuse the BlackFriday instance when possible
This is in heavy use in rendering, so this makes a difference:
```bash
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 124551144 107743429 -13.49%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 528684 435118 -17.70%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 53306848 45147832 -15.31%
```
2017-12-16 12:56:58 -05:00
renderingConfig * helpers . BlackFriday
2016-11-16 11:52:03 -05:00
// menus
2016-11-16 14:32:38 -05:00
pageMenus PageMenus
2016-11-16 11:52:03 -05:00
2018-10-20 13:09:03 -04:00
source . File
2016-11-16 11:52:03 -05:00
2015-05-23 06:28:01 -04:00
Position ` json:"-" `
2016-11-02 16:34:19 -04:00
2016-11-01 18:04:12 -04:00
GitInfo * gitmap . GitInfo
2016-10-31 14:53:33 -04:00
// This was added as part of getting the Nodes (taxonomies etc.) to work as
// Pages in Hugo 0.18.
// It is deliberately named similar to Section, but not exported (for now).
// We currently have only one level of section in Hugo, but the page can live
// any number of levels down the file path.
// To support taxonomies like /categories/hugo etc. we will need to keep track
// of that information in a general way.
// So, sections represents the path to the content, i.e. a content file or a
// virtual content file in the situations where a taxonomy or a section etc.
// isn't accomanied by one.
sections [ ] string
2017-04-09 04:33:04 -04:00
// Will only be set for sections and regular pages.
parent * Page
// When we create paginator pages, we create a copy of the original,
// but keep track of it here.
origOnCopy * Page
// Will only be set for section pages and the home page.
subSections Pages
2017-01-03 11:28:51 -05:00
s * Site
2016-11-13 08:27:10 -05:00
2016-11-16 15:06:10 -05:00
// Pulled over from old Node. TODO(bep) reorg and group (embed)
2016-11-13 08:27:10 -05:00
Site * SiteInfo ` json:"-" `
2018-01-15 14:40:39 -05:00
title string
2016-11-13 08:27:10 -05:00
Description string
Keywords [ ] 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
data map [ string ] interface { }
2016-11-13 08:27:10 -05: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
pagemeta . PageDates
2016-11-13 08:27:10 -05:00
Sitemap Sitemap
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
pagemeta . URLPath
frontMatterURL string
2018-01-05 05:07:50 -05:00
permalink string
relPermalink 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
// relative target path without extension and any base path element
// from the baseURL or the language code.
2018-01-05 05:07:50 -05:00
// This is used to construct paths in the page resources.
2018-01-10 04:20:08 -05:00
relTargetPathBase string
2018-01-20 11:11:03 -05:00
// Is set to a forward slashed path if this is a Page resources living in a folder below its owner.
resourcePath string
2016-11-13 08:27:10 -05:00
2018-01-23 08:02:54 -05:00
// This is enabled if it is a leaf bundle (the "index.md" type) and it is marked as headless in front matter.
// Being headless means that
// 1. The page itself is not rendered to disk
// 2. It is not available in .Site.Pages etc.
// 3. But you can get it via .Site.GetPage
headless bool
2017-03-18 11:46:10 -04:00
layoutDescriptor output . LayoutDescriptor
2018-07-06 08:12:10 -04:00
scratch * maps . Scratch
2016-11-13 08:27:10 -05:00
2017-02-04 22:20:06 -05:00
// It would be tempting to use the language set on the Site, but in they way we do
// multi-site processing, these values may differ during the initial page processing.
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
language * langs . Language
2017-02-04 22:20:06 -05:00
lang string
2017-03-02 09:35:25 -05:00
2018-08-16 04:58:05 -04:00
// When in Fast Render Mode, we only render a sub set of the pages, i.e. the
// pages the user is working on. There are, however, situations where we need to
// signal other pages to be rendered.
forceRender bool
2017-03-16 03:32:14 -04:00
// The output formats this page will be rendered to.
outputFormats output . Formats
2017-03-06 07:18:33 -05:00
2017-03-16 03:32:14 -04:00
// This is the PageOutput that represents the first item in outputFormats.
2017-03-09 13:19:29 -05:00
// Use with care, as there are potential for inifinite loops.
mainPageOutput * PageOutput
2017-03-17 11:35:09 -04:00
targetPathDescriptorPrototype * targetPathDescriptor
2017-03-06 07:18:33 -05:00
}
2018-07-07 05:40:47 -04:00
func stackTrace ( length int ) string {
trace := make ( [ ] byte , length )
2018-04-23 23:57:33 -04:00
runtime . Stack ( trace , true )
return string ( trace )
}
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
func ( p * Page ) Data ( ) interface { } {
return p . data
}
2018-04-19 12:06:40 -04:00
func ( p * Page ) initContent ( ) {
2018-04-23 23:57:33 -04:00
2018-04-19 12:06:40 -04:00
p . contentInit . Do ( func ( ) {
// This careful dance is here to protect against circular loops in shortcode/content
// constructs.
// TODO(bep) context vs the remote shortcodes
ctx , cancel := context . WithTimeout ( context . Background ( ) , p . s . Timeout )
defer cancel ( )
c := make ( chan error , 1 )
2018-10-30 06:15:15 -04:00
p . contentInitMu . Lock ( )
defer p . contentInitMu . Unlock ( )
2018-04-19 12:06:40 -04:00
go func ( ) {
var err error
2018-11-06 04:04:37 -05:00
err = p . prepareContent ( )
2018-04-23 23:57:33 -04:00
if err != nil {
2018-10-03 08:58:09 -04:00
c <- err
2018-04-23 23:57:33 -04:00
return
2018-04-19 12:06:40 -04:00
}
2018-04-23 23:57:33 -04:00
2018-10-30 06:15:15 -04:00
select {
case <- ctx . Done ( ) :
return
default :
}
2018-04-19 12:06:40 -04:00
if len ( p . summary ) == 0 {
if err = p . setAutoSummary ( ) ; err != nil {
2018-10-21 06:20:21 -04:00
err = p . errorf ( err , "failed to set auto summary" )
2018-04-19 12:06:40 -04:00
}
}
c <- err
} ( )
select {
case <- ctx . Done ( ) :
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
p . s . Log . WARN . Printf ( "Timed out creating content for page %q (.Content will be empty). This is most likely a circular shortcode content loop that should be fixed. If this is just a shortcode calling a slow remote service, try to set \"timeout=30000\" (or higher, value is in milliseconds) in config.toml.\n" , p . pathOrTitle ( ) )
2018-04-19 12:06:40 -04:00
case err := <- c :
if err != nil {
2018-10-21 06:20:21 -04:00
p . s . SendError ( err )
2018-04-19 12:06:40 -04:00
}
}
} )
2018-10-21 06:20:21 -04:00
2018-04-19 12:06:40 -04:00
}
// This is sent to the shortcodes for this page. Not doing that will create an infinite regress. So,
// shortcodes can access .Page.TableOfContents, but not .Page.Content etc.
func ( p * Page ) withoutContent ( ) * PageWithoutContent {
p . pageInit . withoutContentInit . Do ( func ( ) {
p . pageWithoutContent = & PageWithoutContent { Page : p }
} )
return p . pageWithoutContent
}
2018-04-15 10:42:54 -04:00
func ( p * Page ) Content ( ) ( interface { } , error ) {
2018-04-19 12:06:40 -04:00
return p . content ( ) , nil
}
func ( p * Page ) Truncated ( ) bool {
p . initContent ( )
return p . truncated
}
func ( p * Page ) content ( ) template . HTML {
p . initContent ( )
return p . contentv
}
func ( p * Page ) Summary ( ) template . HTML {
p . initContent ( )
return p . summary
2018-04-15 10:42:54 -04:00
}
2018-03-15 04:37:30 -04:00
// Sites is a convenience method to get all the Hugo sites/languages configured.
func ( p * Page ) Sites ( ) SiteInfos {
infos := make ( SiteInfos , len ( p . s . owner . Sites ) )
for i , site := range p . s . owner . Sites {
infos [ i ] = & site . Info
}
return infos
}
2017-08-19 07:16:00 -04:00
// SearchKeywords implements the related.Document interface needed for fast page searches.
func ( p * Page ) SearchKeywords ( cfg related . IndexConfig ) ( [ ] related . Keyword , error ) {
v , err := p . Param ( cfg . Name )
if err != nil {
return nil , err
}
return cfg . ToKeywords ( v )
}
// PubDate is when this page was or will be published.
// NOTE: This is currently used for search only and is not meant to be used
// directly in templates. We need to consolidate the dates in this struct.
// TODO(bep) see https://github.com/gohugoio/hugo/issues/3854
func ( p * Page ) PubDate ( ) time . Time {
if ! p . PublishDate . IsZero ( ) {
return p . PublishDate
}
return p . Date
}
: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 ( * Page ) ResourceType ( ) string {
return pageResourceType
}
2017-03-24 11:54:37 -04:00
func ( p * Page ) RSSLink ( ) template . URL {
2017-03-25 14:36:50 -04:00
f , found := p . outputFormats . GetByName ( output . RSSFormat . Name )
2017-03-24 11:54:37 -04:00
if ! found {
return ""
}
return template . URL ( newOutputFormat ( p , f ) . Permalink ( ) )
}
2017-03-16 03:58:50 -04:00
func ( p * Page ) createLayoutDescriptor ( ) output . LayoutDescriptor {
var section string
2017-03-06 07:18:33 -05:00
switch p . Kind {
case KindSection :
2017-04-09 04:33:04 -04:00
// In Hugo 0.22 we introduce nested sections, but we still only
// use the first level to pick the correct template. This may change in
// the future.
2017-03-16 03:58:50 -04:00
section = p . sections [ 0 ]
2017-03-06 07:18:33 -05:00
case KindTaxonomy , KindTaxonomyTerm :
2017-03-16 03:58:50 -04:00
section = p . s . taxonomiesPluralSingular [ p . sections [ 0 ] ]
2017-03-06 07:18:33 -05:00
default :
2017-03-16 03:58:50 -04:00
}
return output . LayoutDescriptor {
2018-07-09 04:29:18 -04:00
Kind : p . Kind ,
Type : p . Type ( ) ,
Lang : p . Lang ( ) ,
Layout : p . Layout ,
Section : section ,
2017-03-06 07:18:33 -05:00
}
2016-11-16 14:32:38 -05:00
}
// pageInit lazy initializes different parts of the page. It is extracted
// into its own type so we can easily create a copy of a given page.
type pageInit struct {
languageInit sync . Once
pageMenusInit sync . Once
pageMetaInit sync . Once
renderingConfigInit sync . Once
2018-04-19 12:06:40 -04:00
withoutContentInit sync . Once
}
type pageContentInit struct {
contentInitMu sync . Mutex
contentInit sync . Once
plainInit sync . Once
plainWordsInit sync . Once
}
2018-04-23 23:57:33 -04:00
func ( p * Page ) resetContent ( ) {
2018-04-19 12:06:40 -04:00
p . pageContentInit = & pageContentInit { }
2013-07-04 11:32:55 -04:00
}
2016-11-13 06:33:11 -05:00
// IsNode returns whether this is an item of one of the list types in Hugo,
// i.e. not a regular content page.
func ( p * Page ) IsNode ( ) bool {
return p . Kind != KindPage
}
// IsHome returns whether this is the home page.
func ( p * Page ) IsHome ( ) bool {
return p . Kind == KindHome
}
2017-04-09 04:33:04 -04:00
// IsSection returns whether this is a section page.
func ( p * Page ) IsSection ( ) bool {
return p . Kind == KindSection
}
2016-11-13 06:33:11 -05:00
// IsPage returns whether this is a regular content page.
func ( p * Page ) IsPage ( ) bool {
return p . Kind == KindPage
}
2018-04-23 02:41:19 -04:00
// BundleType returns the bundle type: "leaf", "branch" or an empty string if it is none.
// See https://gohugo.io/content-management/page-bundles/
func ( p * Page ) BundleType ( ) string {
if p . IsNode ( ) {
return "branch"
}
2018-10-20 13:09:03 -04:00
var source interface { } = p . File
2018-04-23 02:41:19 -04:00
if fi , ok := source . ( * fileInfo ) ; ok {
switch fi . bundleTp {
case bundleBranch :
return "branch"
case bundleLeaf :
return "leaf"
}
}
return ""
}
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
func ( p * Page ) MediaType ( ) media . Type {
return media . OctetType
}
2013-07-04 11:32:55 -04:00
type PageMeta struct {
2016-08-17 07:41:48 -04:00
wordCount int
fuzzyWordCount int
readingTime int
2014-01-29 17:50:31 -05:00
Weight int
2013-07-04 11:32:55 -04:00
}
type Position struct {
2018-09-24 18:06:29 -04:00
PrevPage * Page
NextPage * Page
2014-04-18 03:23:13 -04:00
PrevInSection * Page
NextInSection * Page
2013-07-04 11:32:55 -04:00
}
type Pages [ ] * Page
2016-01-07 21:48:13 -05:00
2017-03-09 08:18:12 -05:00
func ( ps Pages ) String ( ) string {
return fmt . Sprintf ( "Pages(%d)" , len ( ps ) )
2016-11-13 08:27:10 -05:00
}
2018-03-21 12:21:46 -04:00
func ( ps Pages ) findPagePosByFilename ( filename string ) int {
2016-01-11 12:06:52 -05:00
for i , x := range ps {
2018-10-20 13:09:03 -04:00
if x . Filename ( ) == filename {
2016-01-11 12:06:52 -05:00
return i
}
}
return - 1
}
2016-01-07 21:48:13 -05:00
2017-08-19 07:16:00 -04:00
func ( ps Pages ) removeFirstIfFound ( p * Page ) Pages {
ii := - 1
for i , pp := range ps {
if pp == p {
ii = i
break
}
}
if ii != - 1 {
ps = append ( ps [ : ii ] , ps [ ii + 1 : ] ... )
}
return ps
}
2018-03-21 12:21:46 -04:00
func ( ps Pages ) findPagePosByFilnamePrefix ( prefix string ) int {
2017-06-08 14:00:05 -04:00
if prefix == "" {
return - 1
}
2018-03-21 12:21:46 -04:00
lenDiff := - 1
currPos := - 1
prefixLen := len ( prefix )
// Find the closest match
2017-06-08 14:00:05 -04:00
for i , x := range ps {
2018-10-20 13:09:03 -04:00
if strings . HasPrefix ( x . Filename ( ) , prefix ) {
diff := len ( x . Filename ( ) ) - prefixLen
2018-03-21 12:21:46 -04:00
if lenDiff == - 1 || diff < lenDiff {
lenDiff = diff
currPos = i
}
2017-06-08 14:00:05 -04:00
}
}
2018-03-21 12:21:46 -04:00
return currPos
2017-06-08 14:00:05 -04:00
}
2017-06-08 16:32:01 -04:00
// findPagePos Given a page, it will find the position in Pages
2016-01-07 21:48:13 -05:00
// will return -1 if not found
2017-06-08 16:32:01 -04:00
func ( ps Pages ) findPagePos ( page * Page ) int {
2016-01-07 21:48:13 -05:00
for i , x := range ps {
2018-10-20 13:09:03 -04:00
if x . Filename ( ) == page . Filename ( ) {
2016-01-07 21:48:13 -05:00
return i
}
}
return - 1
}
2014-01-27 17:16:28 -05:00
func ( p * Page ) Plain ( ) string {
2018-04-19 12:06:40 -04:00
p . initContent ( )
p . initPlain ( true )
2014-01-29 17:50:31 -05:00
return p . plain
2013-10-15 09:15:52 -04:00
}
2018-04-19 12:06:40 -04:00
func ( p * Page ) initPlain ( lock bool ) {
2015-02-04 18:38:50 -05:00
p . plainInit . Do ( func ( ) {
2018-04-19 12:06:40 -04:00
if lock {
p . contentInitMu . Lock ( )
defer p . contentInitMu . Unlock ( )
}
p . plain = helpers . StripHTML ( string ( p . contentv ) )
2016-08-16 16:50:15 -04:00
} )
}
2018-04-19 12:06:40 -04:00
func ( p * Page ) PlainWords ( ) [ ] string {
p . initContent ( )
p . initPlainWords ( true )
return p . plainWords
}
func ( p * Page ) initPlainWords ( lock bool ) {
2016-08-16 16:50:15 -04:00
p . plainWordsInit . Do ( func ( ) {
2018-04-19 12:06:40 -04:00
if lock {
p . contentInitMu . Lock ( )
defer p . contentInitMu . Unlock ( )
}
p . plainWords = strings . Fields ( p . plain )
2015-07-12 05:28:19 -04:00
} )
}
2015-10-11 23:51:04 -04:00
// Param is a convenience method to do lookups in Page's and Site's Params map,
// in that order.
//
2016-10-17 13:30:21 -04:00
// This method is also implemented on Node and SiteInfo.
2015-10-11 23:51:04 -04:00
func ( p * Page ) Param ( key interface { } ) ( interface { } , error ) {
keyStr , err := cast . ToStringE ( key )
if err != nil {
return nil , err
}
2017-02-19 02:50:08 -05:00
2016-10-17 13:30:21 -04:00
keyStr = strings . ToLower ( keyStr )
2017-02-19 02:50:08 -05:00
result , _ := p . traverseDirect ( keyStr )
if result != nil {
return result , nil
}
keySegments := strings . Split ( keyStr , "." )
if len ( keySegments ) == 1 {
return nil , nil
}
return p . traverseNested ( keySegments )
}
func ( p * Page ) traverseDirect ( key string ) ( interface { } , error ) {
keyStr := strings . ToLower ( key )
2018-01-15 14:40:39 -05:00
if val , ok := p . params [ keyStr ] ; ok {
2015-10-11 23:51:04 -04:00
return val , nil
}
2017-02-19 02:50:08 -05:00
2015-10-11 23:51:04 -04:00
return p . Site . Params [ keyStr ] , nil
}
2017-02-19 02:50:08 -05:00
func ( p * Page ) traverseNested ( keySegments [ ] string ) ( interface { } , error ) {
2018-01-15 14:40:39 -05:00
result := traverse ( keySegments , p . params )
2017-02-19 02:50:08 -05:00
if result != nil {
return result , nil
}
result = traverse ( keySegments , p . Site . Params )
if result != nil {
return result , nil
}
// Didn't find anything, but also no problems.
return nil , nil
}
func traverse ( keys [ ] string , m map [ string ] interface { } ) interface { } {
// Shift first element off.
firstKey , rest := keys [ 0 ] , keys [ 1 : ]
result := m [ firstKey ]
// No point in continuing here.
if result == nil {
return result
}
if len ( rest ) == 0 {
// That was the last key.
return result
}
2017-09-25 22:25:33 -04:00
// That was not the last key.
return traverse ( rest , cast . ToStringMap ( result ) )
2017-02-19 02:50:08 -05:00
}
2014-12-09 13:33:55 -05:00
func ( p * Page ) Author ( ) Author {
authors := p . Authors ( )
2016-09-18 13:10:11 -04:00
for _ , author := range authors {
return author
2016-09-11 04:46:56 -04:00
}
2016-09-18 13:10:11 -04:00
return Author { }
}
2016-09-15 22:28:13 -04:00
2016-09-18 13:10:11 -04:00
func ( p * Page ) Authors ( ) AuthorList {
2018-01-15 14:40:39 -05:00
authorKeys , ok := p . params [ "authors" ]
2016-09-18 13:10:11 -04:00
if ! ok {
return AuthorList { }
}
authors := authorKeys . ( [ ] string )
if len ( authors ) < 1 || len ( p . Site . Authors ) < 1 {
return AuthorList { }
2014-12-09 13:33:55 -05:00
}
2016-09-18 13:10:11 -04:00
al := make ( AuthorList )
for _ , author := range authors {
a , ok := p . Site . Authors [ author ]
if ok {
al [ author ] = a
2014-12-09 13:33:55 -05:00
}
}
2016-09-18 13:10:11 -04:00
return al
2014-12-09 13:33:55 -05:00
}
2015-03-11 13:34:57 -04:00
func ( p * Page ) UniqueID ( ) string {
2018-10-20 13:09:03 -04:00
return p . File . UniqueID ( )
2014-10-01 14:26:43 -04:00
}
2018-10-19 05:30:57 -04:00
// Returns the page as summary and main.
func ( p * Page ) setUserDefinedSummary ( rawContentCopy [ ] byte ) ( * summaryContent , error ) {
Shortcode rewrite, take 2
This commit contains a restructuring and partial rewrite of the shortcode handling.
Prior to this commit rendering of the page content was mingled with handling of the shortcodes. This led to several oddities.
The new flow is:
1. Shortcodes are extracted from page and replaced with placeholders.
2. Shortcodes are processed and rendered
3. Page is processed
4. The placeholders are replaced with the rendered shortcodes
The handling of summaries is also made simpler by this.
This commit also introduces some other chenges:
1. distinction between shortcodes that need further processing and those who do not:
* `{{< >}}`: Typically raw HTML. Will not be processed.
* `{{% %}}`: Will be processed by the page's markup engine (Markdown or (infuture) Asciidoctor)
The above also involves a new shortcode-parser, with lexical scanning inspired by Rob Pike's talk called "Lexical Scanning in Go",
which should be easier to understand, give better error messages and perform better.
2. If you want to exclude a shortcode from being processed (for documentation etc.), the inner part of the shorcode must be commented out, i.e. `{{%/* movie 47238zzb */%}}`. See the updated shortcode section in the documentation for further examples.
The new parser supports nested shortcodes. This isn't new, but has two related design choices worth mentioning:
* The shortcodes will be rendered individually, so If both `{{< >}}` and `{{% %}}` are used in the nested hierarchy, one will be passed through the page's markdown processor, the other not.
* To avoid potential costly overhead of always looking far ahead for a possible closing tag, this implementation looks at the template itself, and is branded as a container with inner content if it contains a reference to `.Inner`
Fixes #565
Fixes #480
Fixes #461
And probably some others.
2014-10-27 16:48:30 -04:00
2016-10-25 14:40:32 -04:00
sc , err := splitUserDefinedSummaryAndContent ( p . Markup , rawContentCopy )
2016-10-18 02:43:44 -04:00
if err != nil {
return nil , err
}
2015-05-10 07:33:50 -04:00
2016-08-01 17:04:44 -04:00
if sc == nil {
// No divider found
return nil , nil
}
2015-02-04 18:38:50 -05:00
2018-04-19 12:06:40 -04:00
p . summary = helpers . BytesToHTML ( sc . summary )
2016-08-01 17:04:44 -04:00
return sc , nil
}
// Make this explicit so there is no doubt about what is what.
type summaryContent struct {
2017-01-26 14:58:25 -05:00
summary [ ] byte
content [ ] byte
2016-08-01 17:04:44 -04:00
}
2016-10-18 02:43:44 -04:00
func splitUserDefinedSummaryAndContent ( markup string , c [ ] byte ) ( sc * summaryContent , err error ) {
defer func ( ) {
if r := recover ( ) ; r != nil {
err = fmt . Errorf ( "summary split failed: %s" , r )
}
} ( )
2018-10-30 15:24:34 -04:00
startDivider := bytes . Index ( c , internalSummaryDividerBaseBytes )
2016-08-01 17:04:44 -04:00
if startDivider == - 1 {
2016-10-18 02:43:44 -04:00
return
2016-08-01 17:04:44 -04:00
}
2018-10-30 15:24:34 -04:00
startTag := "p"
2016-08-01 17:04:44 -04:00
switch markup {
case "asciidoc" :
2018-10-30 15:24:34 -04:00
startTag = "div"
}
// Walk back and forward to the surrounding tags.
start := bytes . LastIndex ( c [ : startDivider ] , [ ] byte ( "<" + startTag ) )
end := bytes . Index ( c [ startDivider : ] , [ ] byte ( "</" + startTag ) )
if start == - 1 {
start = startDivider
} else {
start = startDivider - ( startDivider - start )
2016-08-01 17:04:44 -04:00
}
2018-10-30 15:24:34 -04:00
if end == - 1 {
end = startDivider + len ( internalSummaryDividerBase )
} else {
end = startDivider + end + len ( startTag ) + 3
2016-10-18 02:43:44 -04:00
}
2016-08-01 17:04:44 -04:00
2018-10-30 15:24:34 -04:00
var addDiv bool
switch markup {
case "rst" :
addDiv = true
2016-08-01 17:04:44 -04:00
}
2018-10-30 15:24:34 -04:00
withoutDivider := append ( c [ : start ] , bytes . Trim ( c [ end : ] , "\n" ) ... )
var summary [ ] byte
2016-08-07 17:34:04 -04:00
if len ( withoutDivider ) > 0 {
2018-10-30 15:24:34 -04:00
summary = bytes . TrimSpace ( withoutDivider [ : start ] )
2016-08-07 17:34:04 -04:00
}
2016-08-01 17:04:44 -04:00
if addDiv {
// For the rst
summary = append ( append ( [ ] byte ( nil ) , summary ... ) , [ ] byte ( "</div>" ) ... )
}
2016-10-18 02:43:44 -04:00
if err != nil {
return
}
sc = & summaryContent {
2017-01-26 14:58:25 -05:00
summary : summary ,
2018-10-30 15:24:34 -04:00
content : bytes . TrimSpace ( withoutDivider ) ,
2016-08-01 17:04:44 -04:00
}
2016-10-18 02:43:44 -04:00
return
2016-08-01 17:04:44 -04:00
}
func ( p * Page ) setAutoSummary ( ) error {
var summary string
var truncated bool
2018-04-19 12:06:40 -04:00
// This careful init dance could probably be refined, but it is purely for performance
// reasons. These "plain" methods are expensive if the plain content is never actually
// used.
p . initPlain ( false )
2016-08-01 17:04:44 -04:00
if p . isCJKLanguage {
2018-04-19 12:06:40 -04:00
p . initPlainWords ( false )
summary , truncated = p . s . ContentSpec . TruncateWordsByRune ( p . plainWords )
2016-08-01 17:04:44 -04:00
} else {
2018-04-19 12:06:40 -04:00
summary , truncated = p . s . ContentSpec . TruncateWordsToWholeSentence ( p . plain )
2016-08-01 17:04:44 -04:00
}
2018-04-19 12:06:40 -04:00
p . summary = template . HTML ( summary )
p . truncated = truncated
2016-08-01 17:04:44 -04:00
return nil
2018-04-19 12:06:40 -04:00
2014-01-27 17:16:28 -05:00
}
2014-01-28 23:11:05 -05:00
func ( p * Page ) renderContent ( content [ ] byte ) [ ] byte {
2017-02-04 22:20:06 -05:00
return p . s . ContentSpec . RenderBytes ( & helpers . RenderingContext {
2018-05-04 20:17:16 -04:00
Content : content , RenderTOC : true , PageFmt : p . Markup ,
2017-02-04 22:20:06 -05:00
Cfg : p . Language ( ) ,
DocumentID : p . UniqueID ( ) , DocumentName : p . Path ( ) ,
2017-08-02 15:37:03 -04:00
Config : p . getRenderingConfig ( ) } )
2014-11-28 15:16:57 -05:00
}
Reuse the BlackFriday instance when possible
This is in heavy use in rendering, so this makes a difference:
```bash
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 124551144 107743429 -13.49%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 528684 435118 -17.70%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 53306848 45147832 -15.31%
```
2017-12-16 12:56:58 -05:00
func ( p * Page ) getRenderingConfig ( ) * helpers . BlackFriday {
2015-01-25 06:08:02 -05:00
p . renderingConfigInit . Do ( func ( ) {
2017-12-29 02:58:38 -05:00
bfParam := p . getParamToLower ( "blackfriday" )
2017-04-06 16:29:37 -04:00
if bfParam == nil {
Reuse the BlackFriday instance when possible
This is in heavy use in rendering, so this makes a difference:
```bash
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 124551144 107743429 -13.49%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 528684 435118 -17.70%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 53306848 45147832 -15.31%
```
2017-12-16 12:56:58 -05:00
p . renderingConfig = p . s . ContentSpec . BlackFriday
2017-04-06 16:29:37 -04:00
return
}
Reuse the BlackFriday instance when possible
This is in heavy use in rendering, so this makes a difference:
```bash
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 124551144 107743429 -13.49%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 528684 435118 -17.70%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 53306848 45147832 -15.31%
```
2017-12-16 12:56:58 -05:00
// Create a copy so we can modify it.
bf := * p . s . ContentSpec . BlackFriday
p . renderingConfig = & bf
if p . Language ( ) == nil {
panic ( fmt . Sprintf ( "nil language for %s with source lang %s" , p . BaseFileName ( ) , p . lang ) )
}
2017-04-06 16:29:37 -04:00
pageParam := cast . ToStringMap ( bfParam )
if err := mapstructure . Decode ( pageParam , & p . renderingConfig ) ; err != nil {
2017-01-10 04:55:03 -05:00
p . s . Log . FATAL . Printf ( "Failed to get rendering config for %s:\n%s" , p . BaseFileName ( ) , err . Error ( ) )
2015-01-25 06:08:02 -05:00
}
2016-10-16 13:28:21 -04:00
2015-01-21 09:28:05 -05:00
} )
2014-11-28 15:16:57 -05:00
2015-01-25 06:08:02 -05:00
return p . renderingConfig
2015-01-21 08:35:33 -05:00
}
2017-01-03 11:28:51 -05:00
func ( s * Site ) newPage ( filename string ) * 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
fi := newFileInfo (
s . SourceSpec ,
s . absContentDir ( ) ,
filename ,
nil ,
bundleNot ,
)
return s . newPageFromFile ( fi )
}
func ( s * Site ) newPageFromFile ( fi * fileInfo ) * Page {
return & Page {
2018-04-19 12:06:40 -04:00
pageInit : & pageInit { } ,
pageContentInit : & pageContentInit { } ,
Kind : kindFromFileInfo ( fi ) ,
contentType : "" ,
2018-10-20 13:09:03 -04:00
File : fi ,
2018-04-19 12:06:40 -04:00
Keywords : [ ] string { } , Sitemap : Sitemap { Priority : - 1 } ,
2018-01-15 14:40:39 -05:00
params : make ( map [ string ] interface { } ) ,
2016-07-25 16:22:09 -04:00
translations : make ( Pages , 0 ) ,
2018-01-27 12:03:06 -05:00
sections : sectionsFromFile ( fi ) ,
2017-02-04 22:20:06 -05:00
Site : & s . Info ,
s : s ,
2016-05-14 00:35:16 -04:00
}
2013-08-13 19:39:24 -04:00
}
2013-07-04 11:32:55 -04:00
2013-09-18 13:17:43 -04:00
func ( p * Page ) IsRenderable ( ) bool {
2014-01-29 17:50:31 -05:00
return p . renderable
2013-09-18 13:17:43 -04:00
}
2015-03-07 06:25:38 -05:00
func ( p * Page ) Type ( ) string {
if p . contentType != "" {
return p . contentType
2014-01-29 17:50:31 -05:00
}
2014-10-16 20:20:09 -04:00
2015-03-07 06:25:38 -05:00
if x := p . Section ( ) ; x != "" {
2014-01-29 17:50:31 -05:00
return x
}
2013-07-04 11:32:55 -04:00
2014-01-29 17:50:31 -05:00
return "page"
2013-07-04 11:32:55 -04:00
}
2017-04-09 04:33:04 -04:00
// Section returns the first path element below the content root. Note that
// since Hugo 0.22 we support nested sections, but this will always be the first
// element of any nested path.
2015-03-07 06:25:38 -05:00
func ( p * Page ) Section ( ) string {
2017-11-06 22:58:41 -05:00
if p . Kind == KindSection || p . Kind == KindTaxonomy || p . Kind == KindTaxonomyTerm {
2017-02-20 03:33:35 -05:00
return p . sections [ 0 ]
}
2018-10-20 13:09:03 -04:00
return p . File . Section ( )
2014-10-16 20:20:09 -04:00
}
2018-10-18 04:21:23 -04:00
func ( s * Site ) newPageFrom ( buf io . Reader , name string ) ( * Page , error ) {
2017-01-03 11:28:51 -05:00
p , err := s . NewPage ( name )
2014-05-01 14:11:56 -04:00
if err != nil {
return p , err
}
2015-04-03 15:41:12 -04:00
_ , err = p . ReadFrom ( buf )
2018-10-18 04:21:23 -04:00
if err != nil {
return nil , err
}
2014-05-01 14:11:56 -04:00
return p , err
}
2017-01-03 11:28:51 -05:00
func ( s * Site ) NewPage ( name string ) ( * Page , error ) {
2014-01-29 17:50:31 -05:00
if len ( name ) == 0 {
return nil , errors . New ( "Zero length page name" )
}
2013-08-05 10:53:58 -04:00
2014-01-29 17:50:31 -05:00
// Create new page
2017-01-03 11:28:51 -05:00
p := s . newPage ( name )
p . s = s
p . Site = & s . Info
2013-08-05 10:53:58 -04:00
2014-05-01 13:20:58 -04:00
return p , nil
}
2015-04-03 15:41:12 -04:00
func ( p * Page ) ReadFrom ( buf io . Reader ) ( int64 , error ) {
2014-01-29 17:50:31 -05:00
// Parse for metadata & body
2015-04-03 15:41:12 -04:00
if err := p . parse ( buf ) ; err != nil {
2018-10-21 06:20:21 -04:00
return 0 , p . errWithFileContext ( err )
2018-10-03 08:58:09 -04:00
2014-01-29 17:50:31 -05:00
}
2013-08-05 10:53:58 -04:00
2018-10-18 04:21:23 -04:00
if err := p . mapContent ( ) ; err != nil {
2018-10-21 06:20:21 -04:00
return 0 , p . errWithFileContext ( err )
2018-10-18 04:21:23 -04:00
}
2018-10-21 06:20:21 -04:00
return int64 ( len ( p . source . parsed . Input ( ) ) ) , nil
2013-07-04 11:32:55 -04:00
}
2016-08-17 07:41:48 -04:00
func ( p * Page ) WordCount ( ) int {
2018-04-27 04:17:01 -04:00
p . initContentPlainAndMeta ( )
2016-08-17 07:41:48 -04:00
return p . wordCount
}
func ( p * Page ) ReadingTime ( ) int {
2018-04-27 04:17:01 -04:00
p . initContentPlainAndMeta ( )
2016-08-17 07:41:48 -04:00
return p . readingTime
}
func ( p * Page ) FuzzyWordCount ( ) int {
2018-04-27 04:17:01 -04:00
p . initContentPlainAndMeta ( )
2016-08-17 07:41:48 -04:00
return p . fuzzyWordCount
}
2018-04-27 04:17:01 -04:00
func ( p * Page ) initContentPlainAndMeta ( ) {
2018-04-19 12:06:40 -04:00
p . initContent ( )
2018-04-27 04:17:01 -04:00
p . initPlain ( true )
p . initPlainWords ( true )
p . initMeta ( )
}
func ( p * Page ) initContentAndMeta ( ) {
p . initContent ( )
p . initMeta ( )
}
func ( p * Page ) initMeta ( ) {
2016-08-17 07:41:48 -04:00
p . pageMetaInit . Do ( func ( ) {
if p . isCJKLanguage {
p . wordCount = 0
2018-04-19 12:06:40 -04:00
for _ , word := range p . plainWords {
2016-08-17 07:41:48 -04:00
runeCount := utf8 . RuneCountInString ( word )
if len ( word ) == runeCount {
p . wordCount ++
} else {
p . wordCount += runeCount
}
2015-09-03 06:22:20 -04:00
}
2016-08-17 07:41:48 -04:00
} else {
2018-04-19 12:06:40 -04:00
p . wordCount = helpers . TotalWords ( p . plain )
2015-09-03 06:22:20 -04:00
}
2015-09-03 06:22:20 -04:00
2016-08-17 07:41:48 -04:00
// TODO(bep) is set in a test. Fix that.
if p . fuzzyWordCount == 0 {
p . fuzzyWordCount = ( p . wordCount + 100 ) / 100 * 100
}
2015-09-03 06:22:20 -04:00
2016-08-17 07:41:48 -04:00
if p . isCJKLanguage {
p . readingTime = ( p . wordCount + 500 ) / 501
} else {
p . readingTime = ( p . wordCount + 212 ) / 213
}
} )
2013-07-04 11:32:55 -04:00
}
2017-07-17 17:20:13 -04:00
// HasShortcode return whether the page has a shortcode with the given name.
// This method is mainly motivated with the Hugo Docs site's need for a list
// of pages with the `todo` shortcode in it.
func ( p * Page ) HasShortcode ( name string ) bool {
if p . shortcodeState == nil {
return false
}
return p . shortcodeState . nameSet [ name ]
}
2016-07-25 16:22:09 -04:00
// AllTranslations returns all translations, including the current Page.
func ( p * Page ) AllTranslations ( ) Pages {
return p . translations
}
2016-08-09 08:26:55 -04:00
// IsTranslated returns whether this content file is translated to
// other language(s).
func ( p * Page ) IsTranslated ( ) bool {
return len ( p . translations ) > 1
}
2016-07-25 16:22:09 -04:00
// Translations returns the translations excluding the current Page.
func ( p * Page ) Translations ( ) Pages {
translations := make ( Pages , 0 )
for _ , t := range p . translations {
2017-02-19 09:00:18 -05:00
if t . Lang ( ) != p . Lang ( ) {
2016-07-25 16:22:09 -04:00
translations = append ( translations , t )
}
}
return translations
}
2017-11-17 10:28:35 -05:00
// TranslationKey returns the key used to map language translations of this page.
// It will use the translationKey set in front matter if set, or the content path and
// filename (excluding any language code and extension), e.g. "about/index".
// The Page Kind is always prepended.
func ( p * Page ) TranslationKey ( ) string {
if p . translationKey != "" {
return p . Kind + "/" + p . translationKey
}
if p . IsNode ( ) {
return path . Join ( p . Kind , path . Join ( p . sections ... ) , p . TranslationBaseName ( ) )
}
return path . Join ( p . Kind , filepath . ToSlash ( p . Dir ( ) ) , p . TranslationBaseName ( ) )
}
2013-10-25 18:37:53 -04:00
func ( p * Page ) LinkTitle ( ) string {
2014-01-29 17:50:31 -05:00
if len ( p . linkTitle ) > 0 {
return p . linkTitle
}
2018-01-15 14:40:39 -05:00
return p . title
2013-10-25 18:37:53 -04:00
}
2016-06-14 09:53:49 -04:00
func ( p * Page ) shouldBuild ( ) 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
return shouldBuild ( p . s . BuildFuture , p . s . BuildExpired ,
p . s . BuildDrafts , p . Draft , p . PublishDate , p . ExpiryDate )
2016-05-11 11:45:09 -04:00
}
2016-06-14 09:53:49 -04:00
func shouldBuild ( buildFuture bool , buildExpired bool , buildDrafts bool , Draft bool ,
2016-05-11 11:45:09 -04:00
publishDate time . Time , expiryDate time . Time ) bool {
if ! ( buildDrafts || ! Draft ) {
return false
2014-05-29 00:48:40 -04:00
}
2016-05-11 11:45:09 -04:00
if ! buildFuture && ! publishDate . IsZero ( ) && publishDate . After ( time . Now ( ) ) {
return false
}
if ! buildExpired && ! expiryDate . IsZero ( ) && expiryDate . Before ( time . Now ( ) ) {
return false
}
return true
2014-05-29 00:48:40 -04:00
}
2015-03-07 06:25:38 -05:00
func ( p * Page ) IsDraft ( ) bool {
return p . Draft
2014-08-20 11:09:35 -04:00
}
2015-03-07 06:25:38 -05:00
func ( p * Page ) IsFuture ( ) bool {
2016-06-13 11:37:10 -04:00
if p . PublishDate . IsZero ( ) {
return false
}
2016-05-11 10:04:53 -04:00
return p . PublishDate . After ( time . Now ( ) )
}
func ( p * Page ) IsExpired ( ) bool {
2016-06-13 11:37:10 -04:00
if p . ExpiryDate . IsZero ( ) {
return false
}
2016-05-11 10:04:53 -04:00
return p . ExpiryDate . Before ( time . Now ( ) )
2014-08-20 11:09:35 -04:00
}
2016-09-14 12:51:34 -04:00
func ( p * Page ) URL ( ) string {
2016-11-15 04:43:49 -05:00
if p . IsPage ( ) && p . URLPath . URL != "" {
2016-09-14 12:51:34 -04:00
// This is the url set in front matter
return p . URLPath . URL
}
// Fall back to the relative permalink.
2016-11-15 04:43:49 -05:00
u := p . RelPermalink ( )
2016-09-14 12:51:34 -04:00
return u
}
2017-03-09 13:19:29 -05:00
// Permalink returns the absolute URL to this Page.
func ( p * Page ) Permalink ( ) string {
2018-01-23 08:02:54 -05:00
if p . headless {
return ""
}
2017-03-09 13:19:29 -05:00
return p . permalink
}
2016-11-15 04:43:49 -05:00
2017-03-09 13:19:29 -05:00
// RelPermalink gets a URL to the resource relative to the host.
func ( p * Page ) RelPermalink ( ) string {
2018-01-23 08:02:54 -05:00
if p . headless {
return ""
}
2017-03-09 13:19:29 -05:00
return p . relPermalink
}
2016-11-15 04:43:49 -05:00
2018-01-15 14:40:39 -05:00
// See resource.Resource
2018-01-20 11:11:03 -05:00
// This value is used, by default, in Resources.ByPrefix etc.
2018-01-15 14:40:39 -05:00
func ( p * Page ) Name ( ) string {
2018-01-20 11:11:03 -05:00
if p . resourcePath != "" {
return p . resourcePath
2018-01-15 14:40:39 -05:00
}
return p . title
}
func ( p * Page ) Title ( ) string {
return p . title
}
func ( p * Page ) Params ( ) map [ string ] interface { } {
return p . params
}
2018-01-10 04:20:08 -05:00
func ( p * Page ) subResourceTargetPathFactory ( base string ) string {
return path . Join ( p . relTargetPathBase , base )
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
}
2018-11-06 04:04:37 -05:00
// Prepare this page for rendering for a new site. The flag start is set
// for the first site and output format.
func ( p * Page ) prepareForRender ( start bool ) error {
p . setContentInit ( start )
if start {
return p . initMainOutputFormat ( )
2018-05-08 04:10:13 -04:00
}
2018-11-06 04:04:37 -05:00
return nil
}
2018-05-08 04:10:13 -04:00
2018-11-06 04:04:37 -05:00
func ( p * Page ) initMainOutputFormat ( ) error {
2018-05-08 04:10:13 -04:00
outFormat := p . outputFormats [ 0 ]
pageOutput , err := newPageOutput ( p , false , false , outFormat )
if err != nil {
2018-10-21 06:20:21 -04:00
return p . errorf ( err , "failed to create output page for type %q" , outFormat . Name )
2018-05-08 04:10:13 -04:00
}
p . mainPageOutput = pageOutput
return nil
}
2018-04-23 23:57:33 -04:00
func ( p * Page ) setContentInit ( start bool ) 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
2018-04-23 23:57:33 -04:00
if start {
// This is a new language.
p . shortcodeState . clearDelta ( )
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
}
2018-04-23 23:57:33 -04:00
updated := true
if p . shortcodeState != nil {
updated = p . shortcodeState . updateDelta ( )
2018-04-19 12:06:40 -04:00
}
2018-04-23 23:57:33 -04:00
if updated {
p . resetContent ( )
2018-04-19 12:06:40 -04:00
}
for _ , r := range p . Resources . ByType ( pageResourceType ) {
2018-04-23 23:57:33 -04:00
p . s . PathSpec . ProcessingStats . Incr ( & p . s . PathSpec . ProcessingStats . Pages )
2018-04-19 12:06:40 -04:00
bp := r . ( * Page )
2018-04-23 23:57:33 -04:00
if start {
bp . shortcodeState . clearDelta ( )
}
2018-04-19 12:06:40 -04:00
if bp . shortcodeState != nil {
2018-04-23 23:57:33 -04:00
updated = bp . shortcodeState . updateDelta ( )
2018-04-19 12:06:40 -04:00
}
2018-04-23 23:57:33 -04:00
if updated {
bp . resetContent ( )
2018-04-19 12:06:40 -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
}
2018-04-19 12:06:40 -04:00
return nil
2018-04-23 23:57:33 -04:00
2018-04-19 12:06:40 -04:00
}
2018-11-06 04:04:37 -05:00
func ( p * Page ) prepareContent ( ) error {
2018-04-19 12:06:40 -04:00
s := p . s
: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 we got this far it means that this is either a new Page pointer
// or a template or similar has changed so wee need to do a rerendering
// of the shortcodes etc.
2018-07-23 09:40:04 -04:00
// If in watch mode or if we have multiple sites or output formats,
: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
// we need to keep the original so we can
// potentially repeat this process on rebuild.
2018-07-23 09:40:04 -04:00
needsACopy := s . running ( ) || len ( s . owner . Sites ) > 1 || len ( p . outputFormats ) > 1
: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 workContentCopy [ ] byte
if needsACopy {
workContentCopy = make ( [ ] byte , len ( p . workContent ) )
copy ( workContentCopy , p . workContent )
} else {
// Just reuse the same slice.
workContentCopy = p . workContent
}
2017-03-23 15:05:10 -04:00
var err error
2018-04-19 12:06:40 -04:00
// Note: The shortcodes in a page cannot access the page content it lives in,
// hence the withoutContent().
if workContentCopy , err = handleShortcodes ( p . withoutContent ( ) , workContentCopy ) ; err != nil {
2018-10-03 08:58:09 -04:00
return err
2017-03-23 15:05:10 -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
2018-10-19 05:30:57 -04:00
if p . Markup != "html" && p . source . hasSummaryDivider {
: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
// Now we know enough to create a summary of the page and count some words
2018-10-19 05:30:57 -04:00
summaryContent , err := p . setUserDefinedSummary ( workContentCopy )
: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 != nil {
s . Log . ERROR . Printf ( "Failed to set user defined summary for page %q: %s" , p . Path ( ) , err )
} else if summaryContent != nil {
workContentCopy = summaryContent . content
}
2018-04-19 12:06:40 -04:00
p . contentv = helpers . BytesToHTML ( workContentCopy )
: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
} else {
2018-04-19 12:06:40 -04:00
p . contentv = helpers . BytesToHTML ( workContentCopy )
2018-04-19 11:40:54 -04:00
}
2017-03-17 11:35:09 -04:00
return nil
2013-10-02 20:00:21 -04:00
}
2018-10-18 04:21:23 -04:00
func ( p * Page ) updateMetaData ( frontmatter map [ string ] interface { } ) error {
2018-01-25 22:54:15 -05:00
if frontmatter == nil {
return errors . New ( "missing frontmatter data" )
2014-05-01 14:11:56 -04:00
}
2016-10-24 16:29:48 -04:00
// Needed for case insensitive fetching of params values
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
maps . ToLower ( frontmatter )
2016-10-24 16:29:48 -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
var mtime time . Time
2018-10-20 13:09:03 -04:00
if p . FileInfo ( ) != nil {
mtime = p . FileInfo ( ) . ModTime ( )
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
}
2018-03-11 13:59:11 -04:00
var gitAuthorDate time . Time
if p . GitInfo != nil {
gitAuthorDate = p . GitInfo . AuthorDate
}
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
descriptor := & pagemeta . FrontMatterDescriptor {
2018-03-11 13:59:11 -04:00
Frontmatter : frontmatter ,
Params : p . params ,
Dates : & p . PageDates ,
PageURLs : & p . URLPath ,
2018-10-16 17:51:48 -04:00
BaseFilename : p . ContentBaseName ( ) ,
2018-03-11 13:59:11 -04:00
ModTime : mtime ,
GitAuthorDate : gitAuthorDate ,
}
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
// Handle the date separately
// TODO(bep) we need to "do more" in this area so this can be split up and
// more easily tested without the Page, but the coupling is strong.
err := p . s . frontmatterHandler . HandleDates ( descriptor )
if err != nil {
p . s . Log . ERROR . Printf ( "Failed to handle dates for page %q: %s" , p . Path ( ) , err )
}
2017-09-08 06:28:15 -04:00
2015-09-03 06:22:20 -04:00
var draft , published , isCJKLanguage * bool
2018-01-25 22:54:15 -05:00
for k , v := range frontmatter {
2014-01-29 17:50:31 -05:00
loki := strings . ToLower ( k )
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
if loki == "published" { // Intentionally undocumented
vv , err := cast . ToBoolE ( v )
if err == nil {
published = & vv
}
// published may also be a date
continue
}
if p . s . frontmatterHandler . IsDateKey ( loki ) {
continue
}
2014-01-29 17:50:31 -05:00
switch loki {
case "title" :
2018-01-15 14:40:39 -05:00
p . title = cast . ToString ( v )
p . params [ loki ] = p . title
2014-01-29 17:50:31 -05:00
case "linktitle" :
2015-03-07 06:25:38 -05:00
p . linkTitle = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . linkTitle
2014-01-29 17:50:31 -05:00
case "description" :
2015-03-07 06:25:38 -05:00
p . Description = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Description
2014-01-29 17:50:31 -05:00
case "slug" :
2015-04-09 12:14:26 -04:00
p . Slug = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Slug
2014-01-29 17:50:31 -05:00
case "url" :
2014-04-05 01:26:43 -04:00
if url := cast . ToString ( v ) ; strings . HasPrefix ( url , "http://" ) || strings . HasPrefix ( url , "https://" ) {
2015-03-18 01:16:54 -04:00
return fmt . Errorf ( "Only relative URLs are supported, %v provided" , url )
2014-01-29 17:50:31 -05:00
}
2016-07-26 13:04:10 -04:00
p . URLPath . URL = cast . ToString ( v )
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
p . frontMatterURL = p . URLPath . URL
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . URLPath . URL
2014-01-29 17:50:31 -05:00
case "type" :
2015-03-07 06:25:38 -05:00
p . contentType = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . contentType
2014-10-16 20:20:09 -04:00
case "extension" , "ext" :
2015-03-07 06:25:38 -05:00
p . extension = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . extension
2014-01-29 17:50:31 -05:00
case "keywords" :
2015-03-07 06:25:38 -05:00
p . Keywords = cast . ToStringSlice ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Keywords
2018-01-23 08:02:54 -05:00
case "headless" :
// For now, only the leaf bundles ("index.md") can be headless (i.e. produce no output).
// We may expand on this in the future, but that gets more complex pretty fast.
if p . TranslationBaseName ( ) == "index" {
p . headless = cast . ToBool ( v )
}
p . params [ loki ] = p . headless
2017-03-08 07:45:33 -05:00
case "outputs" :
2017-03-19 16:09:31 -04:00
o := cast . ToStringSlice ( v )
if len ( o ) > 0 {
2017-03-16 03:32:14 -04:00
// Output formats are exlicitly set in front matter, use those.
2017-04-04 03:12:33 -04:00
outFormats , err := p . s . outputFormatsConfig . GetByNames ( o ... )
2017-03-19 16:09:31 -04:00
2017-03-08 07:45:33 -05:00
if err != nil {
2017-03-16 03:32:14 -04:00
p . s . Log . ERROR . Printf ( "Failed to resolve output formats: %s" , err )
2017-03-08 07:45:33 -05:00
} else {
2017-03-16 03:32:14 -04:00
p . outputFormats = outFormats
2018-01-15 14:40:39 -05:00
p . params [ loki ] = outFormats
2017-03-08 07:45:33 -05:00
}
}
2014-01-29 17:50:31 -05:00
case "draft" :
2015-08-02 02:02:20 -04:00
draft = new ( bool )
* draft = cast . ToBool ( v )
2014-01-29 17:50:31 -05:00
case "layout" :
2015-11-02 11:24:50 -05:00
p . Layout = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Layout
2014-01-29 17:50:31 -05:00
case "markup" :
2015-03-07 06:25:38 -05:00
p . Markup = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Markup
2014-01-29 17:50:31 -05:00
case "weight" :
2015-03-07 06:25:38 -05:00
p . Weight = cast . ToInt ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Weight
2014-01-29 17:50:31 -05:00
case "aliases" :
2015-03-07 06:25:38 -05:00
p . Aliases = cast . ToStringSlice ( v )
for _ , alias := range p . Aliases {
2014-01-29 17:50:31 -05:00
if strings . HasPrefix ( alias , "http://" ) || strings . HasPrefix ( alias , "https://" ) {
return fmt . Errorf ( "Only relative aliases are supported, %v provided" , alias )
}
}
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Aliases
2014-01-29 17:50:31 -05:00
case "status" :
2015-03-07 06:25:38 -05:00
p . Status = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Status
2014-05-06 11:02:56 -04:00
case "sitemap" :
2015-03-07 06:25:38 -05:00
p . Sitemap = parseSitemap ( cast . ToStringMap ( v ) )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . Sitemap
2015-09-03 06:22:20 -04:00
case "iscjklanguage" :
isCJKLanguage = new ( bool )
* isCJKLanguage = cast . ToBool ( v )
2017-11-17 10:28:35 -05:00
case "translationkey" :
p . translationKey = cast . ToString ( v )
2018-01-15 14:40:39 -05:00
p . params [ loki ] = p . translationKey
case "resources" :
var resources [ ] map [ string ] interface { }
handled := true
switch vv := v . ( type ) {
case [ ] map [ interface { } ] interface { } :
for _ , vvv := range vv {
resources = append ( resources , cast . ToStringMap ( vvv ) )
}
case [ ] map [ string ] interface { } :
2018-08-28 16:51:44 -04:00
resources = append ( resources , vv ... )
2018-01-15 14:40:39 -05:00
case [ ] interface { } :
for _ , vvv := range vv {
switch vvvv := vvv . ( type ) {
case map [ interface { } ] interface { } :
resources = append ( resources , cast . ToStringMap ( vvvv ) )
case map [ string ] interface { } :
resources = append ( resources , vvvv )
}
}
default :
handled = false
}
if handled {
p . params [ loki ] = resources
p . resourcesMetadata = resources
break
}
fallthrough
2014-01-29 17:50:31 -05:00
default :
// If not one of the explicit values, store in Params
switch vv := v . ( type ) {
case bool :
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vv
2014-01-29 17:50:31 -05:00
case string :
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vv
2014-01-29 17:50:31 -05:00
case int64 , int32 , int16 , int8 , int :
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vv
2014-01-29 17:50:31 -05:00
case float64 , float32 :
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vv
2014-01-29 17:50:31 -05:00
case time . Time :
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vv
2014-01-29 17:50:31 -05:00
default : // handle array of strings as well
switch vvv := vv . ( type ) {
case [ ] interface { } :
2015-06-25 05:46:09 -04:00
if len ( vvv ) > 0 {
switch vvv [ 0 ] . ( type ) {
2015-07-26 09:28:56 -04:00
case map [ interface { } ] interface { } : // Proper parsing structured array from YAML based FrontMatter
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vvv
2015-07-26 09:28:56 -04:00
case map [ string ] interface { } : // Proper parsing structured array from JSON based FrontMatter
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vvv
2016-12-27 21:08:24 -05:00
case [ ] interface { } :
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vvv
2015-06-25 05:46:09 -04:00
default :
a := make ( [ ] string , len ( vvv ) )
for i , u := range vvv {
a [ i ] = cast . ToString ( u )
}
2018-01-15 14:40:39 -05:00
p . params [ loki ] = a
2015-06-25 05:46:09 -04:00
}
} else {
2018-01-15 14:40:39 -05:00
p . params [ loki ] = [ ] string { }
2014-01-29 17:50:31 -05:00
}
2014-04-23 02:55:43 -04:00
default :
2018-01-15 14:40:39 -05:00
p . params [ loki ] = vv
2014-01-29 17:50:31 -05:00
}
}
}
}
2015-05-14 16:06:36 -04:00
2018-05-04 20:17:16 -04:00
// Try markup explicitly set in the frontmatter
p . Markup = helpers . GuessType ( p . Markup )
if p . Markup == "unknown" {
// Fall back to file extension (might also return "unknown")
2018-10-20 13:09:03 -04:00
p . Markup = helpers . GuessType ( p . Ext ( ) )
2018-05-04 20:17:16 -04:00
}
2015-08-02 02:02:20 -04:00
if draft != nil && published != nil {
p . Draft = * draft
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
p . s . Log . WARN . Printf ( "page %q has both draft and published settings in its frontmatter. Using draft." , p . Filename ( ) )
2015-08-02 02:02:20 -04:00
} else if draft != nil {
p . Draft = * draft
} else if published != nil {
p . Draft = ! * published
}
2018-01-15 14:40:39 -05:00
p . params [ "draft" ] = p . Draft
2015-08-02 02:02:20 -04:00
2015-09-03 06:22:20 -04:00
if isCJKLanguage != nil {
p . isCJKLanguage = * isCJKLanguage
2017-02-04 22:20:06 -05:00
} else if p . s . Cfg . GetBool ( "hasCJKLanguage" ) {
2018-10-21 06:20:21 -04:00
if cjk . Match ( p . source . parsed . Input ( ) ) {
2015-09-03 06:22:20 -04:00
p . isCJKLanguage = true
} else {
p . isCJKLanguage = false
}
}
2018-01-15 14:40:39 -05:00
p . params [ "iscjklanguage" ] = p . isCJKLanguage
2015-09-03 06:22:20 -04:00
2014-01-29 17:50:31 -05:00
return nil
2013-07-04 11:32:55 -04:00
}
2015-03-07 06:25:38 -05:00
func ( p * Page ) GetParam ( key string ) interface { } {
2017-12-29 02:58:38 -05:00
return p . getParam ( key , false )
}
func ( p * Page ) getParamToLower ( key string ) interface { } {
2015-05-31 14:30:53 -04:00
return p . getParam ( key , true )
}
func ( p * Page ) getParam ( key string , stringToLower bool ) interface { } {
2018-01-15 14:40:39 -05:00
v := p . params [ strings . ToLower ( key ) ]
2014-01-29 17:50:31 -05:00
if v == nil {
return nil
}
2016-05-14 00:35:16 -04:00
switch val := v . ( type ) {
2014-01-29 17:50:31 -05:00
case bool :
2016-05-14 00:35:16 -04:00
return val
case string :
if stringToLower {
return strings . ToLower ( val )
}
return val
2014-01-29 17:50:31 -05:00
case int64 , int32 , int16 , int8 , int :
2014-04-05 01:26:43 -04:00
return cast . ToInt ( v )
2014-01-29 17:50:31 -05:00
case float64 , float32 :
2014-04-05 01:26:43 -04:00
return cast . ToFloat64 ( v )
2016-05-14 00:35:16 -04:00
case time . Time :
return val
2014-01-29 17:50:31 -05:00
case [ ] string :
2015-05-31 14:30:53 -04:00
if stringToLower {
2016-05-14 00:35:16 -04:00
return helpers . SliceToLower ( val )
2015-05-31 14:30:53 -04:00
}
2014-11-28 15:16:57 -05:00
return v
2016-05-14 00:35:16 -04:00
case map [ string ] interface { } : // JSON and TOML
return v
case map [ interface { } ] interface { } : // YAML
return v
2014-01-29 17:50:31 -05:00
}
2015-01-24 06:44:35 -05:00
2017-01-10 04:55:03 -05:00
p . s . Log . ERROR . Printf ( "GetParam(\"%s\"): Unknown type %s\n" , key , reflect . TypeOf ( v ) )
2014-01-29 17:50:31 -05:00
return nil
2013-07-04 11:32:55 -04:00
}
2016-11-13 08:27:10 -05:00
func ( p * Page ) HasMenuCurrent ( menuID string , me * MenuEntry ) bool {
2016-11-23 16:06:15 -05:00
sectionPagesMenu := p . Site . sectionPagesMenu
2015-01-06 12:11:06 -05:00
// page is labeled as "shadow-member" of the menu with the same identifier as the section
2017-02-20 03:33:35 -05:00
if sectionPagesMenu != "" {
section := p . Section ( )
if section != "" && sectionPagesMenu == menuID && section == me . Identifier {
return true
}
2015-01-06 12:11:06 -05:00
}
2014-04-23 02:59:19 -04:00
2016-11-13 08:27:10 -05:00
if ! me . HasChildren ( ) {
return false
}
menus := p . Menus ( )
if m , ok := menus [ menuID ] ; ok {
for _ , child := range me . Children {
if child . IsEqual ( m ) {
return true
2014-04-23 02:59:19 -04:00
}
2016-11-13 08:27:10 -05:00
if p . HasMenuCurrent ( menuID , child ) {
return true
}
}
}
if p . IsPage ( ) {
return false
}
// The following logic is kept from back when Hugo had both Page and Node types.
// TODO(bep) consolidate / clean
2018-01-15 14:40:39 -05:00
nme := MenuEntry { Page : p , Name : p . title , URL : p . URL ( ) }
2016-11-13 08:27:10 -05:00
for _ , child := range me . Children {
if nme . IsSameResource ( child ) {
return true
}
if p . HasMenuCurrent ( menuID , child ) {
return true
2014-04-23 02:59:19 -04:00
}
}
return false
}
2016-11-13 08:27:10 -05:00
func ( p * Page ) IsMenuCurrent ( menuID string , inme * MenuEntry ) bool {
2015-03-07 06:25:38 -05:00
menus := p . Menus ( )
2014-04-23 02:59:19 -04:00
2016-11-13 08:27:10 -05:00
if me , ok := menus [ menuID ] ; ok {
if me . IsEqual ( inme ) {
return true
}
}
if p . IsPage ( ) {
return false
}
// The following logic is kept from back when Hugo had both Page and Node types.
// TODO(bep) consolidate / clean
2018-01-15 14:40:39 -05:00
me := MenuEntry { Page : p , Name : p . title , URL : p . URL ( ) }
2016-11-13 08:27:10 -05:00
if ! me . IsSameResource ( inme ) {
return false
}
// this resource may be included in several menus
// search for it to make sure that it is in the menu with the given menuId
if menu , ok := ( * p . Site . Menus ) [ menuID ] ; ok {
for _ , menuEntry := range * menu {
if menuEntry . IsSameResource ( inme ) {
return true
}
descendantFound := p . isSameAsDescendantMenu ( inme , menuEntry )
if descendantFound {
return descendantFound
}
}
2014-04-23 02:59:19 -04:00
}
return false
}
2016-11-13 08:27:10 -05:00
func ( p * Page ) isSameAsDescendantMenu ( inme * MenuEntry , parent * MenuEntry ) bool {
if parent . HasChildren ( ) {
for _ , child := range parent . Children {
if child . IsSameResource ( inme ) {
return true
}
descendantFound := p . isSameAsDescendantMenu ( inme , child )
if descendantFound {
return descendantFound
}
}
}
return false
}
2015-03-07 06:25:38 -05:00
func ( p * Page ) Menus ( ) PageMenus {
p . pageMenusInit . Do ( func ( ) {
p . pageMenus = PageMenus { }
2014-04-23 02:59:19 -04:00
2018-01-15 14:40:39 -05:00
if ms , ok := p . params [ "menu" ] ; ok {
2016-11-15 04:43:49 -05:00
link := p . RelPermalink ( )
2014-04-23 02:59:19 -04:00
2017-12-15 12:49:21 -05:00
me := MenuEntry { Page : p , Name : p . LinkTitle ( ) , Weight : p . Weight , URL : link }
2014-04-23 02:59:19 -04:00
2015-02-04 15:27:27 -05:00
// Could be the name of the menu to attach it to
mname , err := cast . ToStringE ( ms )
2014-04-23 02:59:19 -04:00
2015-02-04 15:27:27 -05:00
if err == nil {
2014-04-23 02:59:19 -04:00
me . Menu = mname
2015-03-07 06:25:38 -05:00
p . pageMenus [ mname ] = & me
2015-02-04 15:27:27 -05:00
return
2014-04-23 02:59:19 -04:00
}
2015-02-04 15:27:27 -05:00
// Could be a slice of strings
mnames , err := cast . ToStringSliceE ( ms )
2014-04-23 02:59:19 -04:00
2015-02-04 15:27:27 -05:00
if err == nil {
for _ , mname := range mnames {
me . Menu = mname
2015-03-07 06:25:38 -05:00
p . pageMenus [ mname ] = & me
2015-02-04 15:27:27 -05:00
}
2016-03-10 04:31:12 -05:00
return
2015-02-04 15:27:27 -05:00
}
2014-04-23 02:59:19 -04:00
2015-02-04 15:27:27 -05:00
// Could be a structured menu entry
menus , err := cast . ToStringMapE ( ms )
2014-04-23 02:59:19 -04:00
if err != nil {
2018-01-15 14:40:39 -05:00
p . s . Log . ERROR . Printf ( "unable to process menus for %q\n" , p . title )
2014-04-23 02:59:19 -04:00
}
2015-02-04 15:27:27 -05:00
for name , menu := range menus {
2017-12-15 12:49:21 -05:00
menuEntry := MenuEntry { Page : p , Name : p . LinkTitle ( ) , URL : link , Weight : p . Weight , Menu : name }
2016-03-10 04:31:12 -05:00
if menu != nil {
2018-01-15 14:40:39 -05:00
p . s . Log . DEBUG . Printf ( "found menu: %q, in %q\n" , name , p . title )
2016-03-10 04:31:12 -05:00
ime , err := cast . ToStringMapE ( menu )
if err != nil {
2018-01-15 14:40:39 -05:00
p . s . Log . ERROR . Printf ( "unable to process menus for %q: %s" , p . title , err )
2016-03-10 04:31:12 -05:00
}
2015-02-04 15:27:27 -05:00
2016-03-22 19:29:39 -04:00
menuEntry . marshallMap ( ime )
2015-02-04 15:27:27 -05:00
}
2015-03-07 06:25:38 -05:00
p . pageMenus [ name ] = & menuEntry
2016-07-28 03:30:58 -04:00
2015-02-04 15:27:27 -05:00
}
2014-04-23 02:59:19 -04:00
}
2015-02-04 15:27:27 -05:00
} )
2014-04-23 02:59:19 -04:00
2015-03-07 06:25:38 -05:00
return p . pageMenus
2014-04-23 02:59:19 -04:00
}
2017-05-06 14:15:28 -04:00
func ( p * Page ) shouldRenderTo ( f output . Format ) bool {
_ , found := p . outputFormats . GetByName ( f . Name )
return found
}
2018-10-23 08:37:09 -04:00
// RawContent returns the un-rendered source content without
// any leading front matter.
2015-07-02 09:32:57 -04:00
func ( p * Page ) RawContent ( ) string {
2018-10-23 08:37:09 -04:00
if p . source . posMainContent == - 1 {
return ""
}
return string ( p . source . parsed . Input ( ) [ p . source . posMainContent : ] )
2015-07-02 09:32:57 -04:00
}
2014-05-01 13:21:37 -04:00
func ( p * Page ) FullFilePath ( ) string {
2015-05-31 12:54:50 -04:00
return filepath . Join ( p . Dir ( ) , p . LogicalName ( ) )
2014-05-01 13:21:37 -04:00
}
2018-05-29 21:35:27 -04:00
// Returns the canonical, absolute fully-qualifed logical reference used by
2018-07-17 05:18:29 -04:00
// methods such as GetPage and ref/relref shortcodes to refer to
// this page. It is prefixed with a "/".
2018-05-29 21:35:27 -04:00
//
2018-07-17 05:18:29 -04:00
// For pages that have a source file, it is returns the path to this file as an
// absolute path rooted in this site's content dir.
// For pages that do not (sections witout content page etc.), it returns the
// virtual path, consistent with where you would add a source file.
2018-05-29 21:35:27 -04:00
func ( p * Page ) absoluteSourceRef ( ) string {
2018-10-20 13:09:03 -04:00
if p . File != nil {
sourcePath := p . Path ( )
2018-07-19 16:39:24 -04:00
if sourcePath != "" {
return "/" + filepath . ToSlash ( sourcePath )
}
2018-07-17 05:18:29 -04:00
}
if len ( p . sections ) > 0 {
2018-05-29 21:35:27 -04:00
// no backing file, return the virtual source path
return "/" + path . Join ( p . sections ... )
}
2018-07-17 05:18:29 -04:00
2018-05-29 21:35:27 -04:00
return ""
}
2016-10-31 05:23:01 -04:00
// Pre render prepare steps
func ( p * Page ) prepareLayouts ( ) error {
// TODO(bep): Check the IsRenderable logic.
2016-11-13 05:43:23 -05:00
if p . Kind == KindPage {
2016-10-31 05:23:01 -04:00
if ! p . IsRenderable ( ) {
2017-03-08 07:45:33 -05:00
self := "__" + p . UniqueID ( )
2018-04-19 12:06:40 -04:00
err := p . s . TemplateHandler ( ) . AddLateTemplate ( self , string ( p . content ( ) ) )
2016-10-31 05:23:01 -04:00
if err != nil {
return err
}
2017-03-25 13:28:38 -04:00
p . selfLayout = self
2016-10-31 05:23:01 -04:00
}
}
2017-03-27 14:43:49 -04:00
2016-10-31 05:23:01 -04:00
return nil
}
2016-10-31 13:03:02 -04:00
func ( p * Page ) prepareData ( s * Site ) error {
2017-04-09 04:33:04 -04:00
if p . Kind != KindSection {
var pages Pages
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
p . data = make ( map [ string ] interface { } )
2017-04-09 04:33:04 -04:00
switch p . Kind {
case KindPage :
case KindHome :
pages = s . RegularPages
case KindTaxonomy :
plural := p . sections [ 0 ]
term := p . sections [ 1 ]
if s . Info . preserveTaxonomyNames {
if v , ok := s . taxonomiesOrigKey [ fmt . Sprintf ( "%s-%s" , plural , term ) ] ; ok {
term = v
}
2016-12-26 13:30:57 -05:00
}
2017-04-09 04:33:04 -04:00
singular := s . taxonomiesPluralSingular [ plural ]
taxonomy := s . Taxonomies [ plural ] . Get ( term )
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
p . data [ singular ] = taxonomy
p . data [ "Singular" ] = singular
p . data [ "Plural" ] = plural
p . data [ "Term" ] = term
2017-04-09 04:33:04 -04:00
pages = taxonomy . Pages ( )
case KindTaxonomyTerm :
plural := p . sections [ 0 ]
singular := s . taxonomiesPluralSingular [ plural ]
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
p . data [ "Singular" ] = singular
p . data [ "Plural" ] = plural
p . data [ "Terms" ] = s . Taxonomies [ plural ]
2017-04-09 04:33:04 -04:00
// keep the following just for legacy reasons
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
p . data [ "OrderedIndex" ] = p . data [ "Terms" ]
p . data [ "Index" ] = p . data [ "Terms" ]
2017-04-09 04:33:04 -04:00
// A list of all KindTaxonomy pages with matching plural
for _ , p := range s . findPagesByKind ( KindTaxonomy ) {
if p . sections [ 0 ] == plural {
pages = append ( pages , p )
}
2017-03-05 15:24:14 -05:00
}
}
2016-10-31 14:53:33 -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
p . data [ "Pages" ] = pages
2017-04-09 04:33:04 -04:00
p . Pages = pages
}
2016-11-11 03:19:16 -05:00
2016-11-11 05:35:55 -05:00
// Now we know enough to set missing dates on home page etc.
p . updatePageDates ( )
2016-10-31 05:23:01 -04:00
return nil
}
2016-11-11 05:35:55 -05:00
func ( p * Page ) updatePageDates ( ) {
2016-11-16 15:06:10 -05:00
// TODO(bep) there is a potential issue with page sorting for home pages
2016-11-11 05:35:55 -05:00
// etc. without front matter dates set, but let us wrap the head around
// that in another time.
2016-11-13 06:33:11 -05:00
if ! p . IsNode ( ) {
2016-11-11 05:35:55 -05:00
return
}
if ! p . Date . IsZero ( ) {
if p . Lastmod . IsZero ( ) {
p . Lastmod = p . Date
}
return
} else if ! p . Lastmod . IsZero ( ) {
if p . Date . IsZero ( ) {
p . Date = p . Lastmod
}
return
}
// Set it to the first non Zero date in children
var foundDate , foundLastMod bool
for _ , child := range p . Pages {
if ! child . Date . IsZero ( ) {
p . Date = child . Date
foundDate = true
}
if ! child . Lastmod . IsZero ( ) {
p . Lastmod = child . Lastmod
foundLastMod = true
}
if foundDate && foundLastMod {
break
}
}
}
2016-11-16 14:32:38 -05:00
// copy creates a copy of this page with the lazy sync.Once vars reset
// so they will be evaluated again, for word count calculations etc.
2018-05-08 04:10:13 -04:00
func ( p * Page ) copy ( initContent bool ) * Page {
2018-04-19 12:06:40 -04:00
p . contentInitMu . Lock ( )
2016-11-16 14:32:38 -05:00
c := * p
2018-04-19 12:06:40 -04:00
p . contentInitMu . Unlock ( )
2017-04-08 12:04:12 -04:00
c . pageInit = & pageInit { }
2018-05-08 04:10:13 -04:00
if initContent {
if len ( p . outputFormats ) < 2 {
panic ( fmt . Sprintf ( "programming error: page %q should not need to rebuild content as it has only %d outputs" , p . Path ( ) , len ( p . outputFormats ) ) )
}
c . pageContentInit = & pageContentInit { }
}
2016-11-16 14:32:38 -05:00
return & c
2016-10-31 05:23:01 -04:00
}
2016-11-13 08:27:10 -05:00
func ( p * Page ) Hugo ( ) * HugoInfo {
return hugoInfo
}
2018-05-29 21:35:27 -04:00
// GetPage looks up a page for the given ref.
// {{ with .GetPage "blog" }}{{ .Title }}{{ end }}
//
// This will return nil when no page could be found, and will return
// an error if the ref is ambiguous.
func ( p * Page ) GetPage ( ref string ) ( * Page , error ) {
2018-07-17 05:18:29 -04:00
return p . s . getPageNew ( p , ref )
2018-05-29 21:35:27 -04:00
}
2016-11-13 08:27:10 -05:00
func ( p * Page ) String ( ) string {
2018-07-17 05:18:29 -04:00
if sourceRef := p . absoluteSourceRef ( ) ; sourceRef != "" {
return fmt . Sprintf ( "Page(%s)" , sourceRef )
2018-05-25 19:59:58 -04:00
}
2018-01-15 14:40:39 -05:00
return fmt . Sprintf ( "Page(%q)" , p . title )
2016-11-13 08:27:10 -05:00
}
// Scratch returns the writable context associated with this Page.
2018-07-06 08:12:10 -04:00
func ( p * Page ) Scratch ( ) * maps . Scratch {
2016-11-13 08:27:10 -05:00
if p . scratch == nil {
2018-07-06 08:12:10 -04:00
p . scratch = maps . NewScratch ( )
2016-11-13 08:27:10 -05:00
}
return p . scratch
}
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 ( p * Page ) Language ( ) * langs . Language {
2016-11-13 08:27:10 -05:00
p . initLanguage ( )
return p . language
}
func ( p * Page ) Lang ( ) string {
// When set, Language can be different from lang in the case where there is a
// content file (doc.sv.md) with language indicator, but there is no language
// config for that language. Then the language will fall back on the site default.
if p . Language ( ) != nil {
return p . Language ( ) . Lang
}
return p . lang
}
2016-11-21 04:11:34 -05:00
func ( p * Page ) isNewTranslation ( candidate * Page ) bool {
2016-12-23 03:52:05 -05:00
if p . Kind != candidate . Kind {
2016-11-13 08:27:10 -05:00
return false
}
if p . Kind == KindPage || p . Kind == kindUnknown {
panic ( "Node type not currently supported for this op" )
}
// At this point, we know that this is a traditional Node (home page, section, taxonomy)
// It represents the same node, but different language, if the sections is the same.
if len ( p . sections ) != len ( candidate . sections ) {
return false
}
for i := 0 ; i < len ( p . sections ) ; i ++ {
if p . sections [ i ] != candidate . sections [ i ] {
return false
}
}
2016-11-21 04:11:34 -05:00
// Finally check that it is not already added.
2016-12-23 03:52:05 -05:00
for _ , translation := range p . translations {
if candidate == translation {
2016-11-21 04:11:34 -05:00
return false
}
}
2016-11-13 08:27:10 -05:00
return true
}
func ( p * Page ) shouldAddLanguagePrefix ( ) bool {
if ! p . Site . IsMultiLingual ( ) {
return false
}
2017-11-02 03:25:20 -04:00
if p . s . owner . IsMultihost ( ) {
return true
}
2016-11-13 08:27:10 -05:00
if p . Lang ( ) == "" {
return false
}
2018-07-18 13:58:39 -04:00
if ! p . Site . defaultContentLanguageInSubdir && p . Lang ( ) == p . s . multilingual ( ) . DefaultLang . Lang {
2016-11-13 08:27:10 -05:00
return false
}
return true
}
func ( p * Page ) initLanguage ( ) {
p . languageInit . Do ( func ( ) {
if p . language != nil {
return
}
2017-02-04 22:20:06 -05:00
2018-07-18 13:58:39 -04:00
ml := p . s . multilingual ( )
2016-11-13 08:27:10 -05:00
if ml == nil {
panic ( "Multilanguage not set" )
}
2017-02-04 22:20:06 -05:00
if p . lang == "" {
p . lang = ml . DefaultLang . Lang
2016-11-13 08:27:10 -05:00
p . language = ml . DefaultLang
return
}
2017-02-04 22:20:06 -05:00
language := ml . Language ( p . lang )
2016-11-13 08:27:10 -05:00
if language == nil {
language = ml . DefaultLang
}
p . language = language
2017-02-04 22:20:06 -05:00
2016-11-13 08:27:10 -05:00
} )
}
func ( p * Page ) LanguagePrefix ( ) string {
return p . Site . LanguagePrefix
}
func ( p * Page ) addLangPathPrefixIfFlagSet ( outfile string , should bool ) string {
if helpers . IsAbsURL ( outfile ) {
return outfile
}
if ! should {
return outfile
}
hadSlashSuffix := strings . HasSuffix ( outfile , "/" )
outfile = "/" + path . Join ( p . Lang ( ) , outfile )
if hadSlashSuffix {
outfile += "/"
}
return outfile
}
2018-01-27 12:03:06 -05:00
func sectionsFromFile ( fi * fileInfo ) [ ] string {
dirname := fi . Dir ( )
2017-12-28 05:32:02 -05:00
dirname = strings . Trim ( dirname , helpers . FilePathSeparator )
if dirname == "" {
return 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
}
2018-01-27 12:03:06 -05:00
parts := strings . Split ( dirname , helpers . FilePathSeparator )
if fi . bundleTp == bundleLeaf && len ( parts ) > 0 {
// my-section/mybundle/index.md => my-section
return parts [ : len ( parts ) - 1 ]
}
return parts
2016-11-13 08:27:10 -05:00
}
2018-01-21 14:40:58 -05:00
func kindFromFileInfo ( fi * fileInfo ) string {
if fi . TranslationBaseName ( ) == "_index" {
if fi . Dir ( ) == "" {
return KindHome
}
// Could be index for section, taxonomy, taxonomy term
// We don't know enough yet to determine which
return kindUnknown
2016-11-13 08:27:10 -05:00
}
2018-01-21 14:40:58 -05:00
return KindPage
2016-11-13 08:27:10 -05:00
}
2016-11-16 11:52:03 -05:00
func ( p * Page ) setValuesForKind ( s * Site ) {
2016-11-13 08:27:10 -05:00
if p . Kind == kindUnknown {
// This is either a taxonomy list, taxonomy term or a section
2016-11-16 11:52:03 -05:00
nodeType := s . kindFromSections ( p . sections )
2016-11-13 08:27:10 -05:00
if nodeType == kindUnknown {
2016-11-16 11:52:03 -05:00
panic ( fmt . Sprintf ( "Unable to determine page kind from %q" , p . sections ) )
2016-11-13 08:27:10 -05:00
}
p . Kind = nodeType
}
2016-11-16 11:52:03 -05:00
2016-11-13 08:27:10 -05:00
switch p . Kind {
case KindHome :
2016-11-15 04:43:49 -05:00
p . URLPath . URL = "/"
2017-04-09 04:33:04 -04:00
case KindPage :
default :
2018-01-12 11:17:10 -05:00
if p . URLPath . URL == "" {
p . URLPath . URL = "/" + path . Join ( p . sections ... ) + "/"
}
2016-11-13 08:27:10 -05:00
}
}
2017-03-26 13:34:30 -04:00
// Used in error logs.
func ( p * Page ) pathOrTitle ( ) string {
2018-10-03 08:58:09 -04:00
if p . Filename ( ) != "" {
2018-10-21 06:20:21 -04:00
return p . Filename ( )
2017-03-26 13:34:30 -04:00
}
2018-01-15 14:40:39 -05:00
return p . title
2017-03-26 13:34:30 -04:00
}
2018-09-24 18:06:29 -04:00
func ( p * Page ) Next ( ) * Page {
2018-09-26 03:26:53 -04:00
// TODO Remove the deprecation notice (but keep PrevPage as an alias) Hugo 0.52
2018-09-24 18:06:29 -04:00
helpers . Deprecated ( "Page" , ".Next" , "Use .PrevPage (yes, not .NextPage)." , false )
return p . PrevPage
}
func ( p * Page ) Prev ( ) * Page {
2018-09-26 03:26:53 -04:00
// TODO Remove the deprecation notice (but keep NextPage as an alias) Hugo 0.52
2018-09-24 18:06:29 -04:00
helpers . Deprecated ( "Page" , ".Prev" , "Use .NextPage (yes, not .PrevPage)." , false )
return p . NextPage
}