2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2013-07-04 11:32:55 -04:00
|
|
|
//
|
2015-11-23 22:16:36 -05:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
2013-07-04 11:32:55 -04:00
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-11-23 22:16:36 -05:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-04 11:32:55 -04:00
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
2014-01-29 17:50:31 -05:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2019-01-02 06:33:26 -05:00
|
|
|
"os"
|
2014-12-07 13:48:00 -05:00
|
|
|
"path"
|
|
|
|
"path/filepath"
|
2019-01-02 06:33:26 -05:00
|
|
|
"sort"
|
2014-12-07 13:48:00 -05:00
|
|
|
"strings"
|
2015-01-25 06:08:02 -05:00
|
|
|
|
2022-02-17 07:04:00 -05:00
|
|
|
"go.uber.org/atomic"
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
"github.com/gohugoio/hugo/identity"
|
|
|
|
|
2019-08-16 09:55:03 -04:00
|
|
|
"github.com/gohugoio/hugo/markup/converter"
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
"github.com/gohugoio/hugo/tpl"
|
2019-08-03 11:27:40 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
"github.com/gohugoio/hugo/hugofs/files"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/bep/gitmap"
|
2013-07-04 11:32:55 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/helpers"
|
2017-05-26 03:51:17 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/common/herrors"
|
|
|
|
"github.com/gohugoio/hugo/parser/metadecoders"
|
2017-05-26 03:51:17 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/parser/pageparser"
|
|
|
|
"github.com/pkg/errors"
|
2017-08-17 04:24:17 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/output"
|
2017-08-19 07:16:00 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/media"
|
|
|
|
"github.com/gohugoio/hugo/source"
|
2018-11-01 06:28:30 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/common/collections"
|
|
|
|
"github.com/gohugoio/hugo/common/text"
|
|
|
|
"github.com/gohugoio/hugo/resources"
|
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
|
|
|
"github.com/gohugoio/hugo/resources/resource"
|
2015-09-03 06:22:20 -04:00
|
|
|
)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
var (
|
|
|
|
_ page.Page = (*pageState)(nil)
|
|
|
|
_ collections.Grouper = (*pageState)(nil)
|
|
|
|
_ collections.Slicer = (*pageState)(nil)
|
2016-11-11 03:19:16 -05:00
|
|
|
)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
var (
|
|
|
|
pageTypesProvider = resource.NewResourceTypesProvider(media.OctetType, pageResourceType)
|
2019-11-27 07:42:36 -05:00
|
|
|
nopPageOutput = &pageOutput{
|
|
|
|
pagePerOutputProviders: nopPagePerOutput,
|
|
|
|
ContentProvider: page.NopPage,
|
|
|
|
TableOfContentsProvider: page.NopPage,
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
)
|
2017-08-19 07:16:00 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// pageContext provides contextual information about this page, for error
|
|
|
|
// logging and similar.
|
|
|
|
type pageContext interface {
|
|
|
|
posOffset(offset int) text.Position
|
|
|
|
wrapError(err error) error
|
2019-08-16 09:55:03 -04:00
|
|
|
getContentConverter() converter.Converter
|
2020-09-07 09:07:10 -04:00
|
|
|
addDependency(dep identity.Provider)
|
2017-08-19 07:16:00 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// wrapErr adds some context to the given error if possible.
|
2022-03-17 17:03:27 -04:00
|
|
|
func wrapErr(err error, ctx any) error {
|
2019-01-02 06:33:26 -05:00
|
|
|
if pc, ok := ctx.(pageContext); ok {
|
|
|
|
return pc.wrapError(err)
|
2017-08-19 07:16:00 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return err
|
: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
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
type pageSiteAdapter struct {
|
|
|
|
p page.Page
|
|
|
|
s *Site
|
2017-03-24 11:54:37 -04:00
|
|
|
}
|
|
|
|
|
2020-09-07 09:07:10 -04:00
|
|
|
func (pa pageSiteAdapter) GetPageWithTemplateInfo(info tpl.Info, ref string) (page.Page, error) {
|
|
|
|
p, err := pa.GetPage(ref)
|
|
|
|
if p != nil {
|
|
|
|
// Track pages referenced by templates/shortcodes
|
|
|
|
// when in server mode.
|
|
|
|
if im, ok := info.(identity.Manager); ok {
|
|
|
|
im.Add(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p, err
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (pa pageSiteAdapter) GetPage(ref string) (page.Page, error) {
|
|
|
|
p, err := pa.s.getPageNew(pa.p, ref)
|
|
|
|
if p == nil {
|
|
|
|
// The nil struct has meaning in some situations, mostly to avoid breaking
|
|
|
|
// existing sites doing $nilpage.IsDescendant($p), which will always return
|
|
|
|
// false.
|
|
|
|
p = page.NilPage
|
2017-03-16 03:58:50 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return p, err
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
type pageState struct {
|
|
|
|
// This slice will be of same length as the number of global slice of output
|
|
|
|
// formats (for all sites).
|
|
|
|
pageOutputs []*pageOutput
|
2016-11-13 06:33:11 -05:00
|
|
|
|
2022-02-17 07:04:00 -05:00
|
|
|
// Used to determine if we can reuse content across output formats.
|
|
|
|
pageOutputTemplateVariationsState *atomic.Uint32
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// This will be shifted out when we start to render a new output format.
|
|
|
|
*pageOutput
|
2016-11-13 06:33:11 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Common for all output formats.
|
|
|
|
*pageCommon
|
2017-04-09 04:33:04 -04:00
|
|
|
}
|
|
|
|
|
2022-02-17 07:04:00 -05:00
|
|
|
func (p *pageState) reusePageOutputContent() bool {
|
|
|
|
return p.pageOutputTemplateVariationsState.Load() == 1
|
|
|
|
}
|
|
|
|
|
2022-03-24 03:12:51 -04:00
|
|
|
func (p *pageState) Err() resource.ResourceError {
|
2021-12-09 10:57:05 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Eq returns whether the current page equals the given page.
|
|
|
|
// This is what's invoked when doing `{{ if eq $page $otherPage }}`
|
2022-03-17 17:03:27 -04:00
|
|
|
func (p *pageState) Eq(other any) bool {
|
2019-01-02 06:33:26 -05:00
|
|
|
pp, err := unwrapPage(other)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
2018-04-23 02:41:19 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return p == pp
|
2018-04-23 02:41:19 -04:00
|
|
|
}
|
|
|
|
|
2020-09-07 09:07:10 -04:00
|
|
|
func (p *pageState) GetIdentity() identity.Identity {
|
2022-01-04 07:07:10 -05:00
|
|
|
return identity.NewPathIdentity(files.ComponentFolderContent, filepath.FromSlash(p.Pathc()))
|
2020-09-07 09:07:10 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) GitInfo() *gitmap.GitInfo {
|
|
|
|
return p.gitInfo
|
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
|
|
|
}
|
|
|
|
|
2022-02-27 13:40:07 -05:00
|
|
|
func (p *pageState) CodeOwners() []string {
|
2022-02-18 15:28:02 -05:00
|
|
|
return p.codeowners
|
|
|
|
}
|
|
|
|
|
2020-02-19 03:16:27 -05:00
|
|
|
// GetTerms gets the terms defined on this page in the given taxonomy.
|
2020-06-15 10:33:09 -04:00
|
|
|
// The pages returned will be ordered according to the front matter.
|
2020-02-19 03:16:27 -05:00
|
|
|
func (p *pageState) GetTerms(taxonomy string) page.Pages {
|
2020-05-21 05:25:00 -04:00
|
|
|
if p.treeRef == nil {
|
|
|
|
return nil
|
2020-02-19 03:16:27 -05:00
|
|
|
}
|
|
|
|
|
2020-05-21 05:25:00 -04:00
|
|
|
m := p.s.pageMap
|
|
|
|
|
|
|
|
taxonomy = strings.ToLower(taxonomy)
|
|
|
|
prefix := cleanSectionTreeKey(taxonomy)
|
|
|
|
self := strings.TrimPrefix(p.treeRef.key, "/")
|
|
|
|
|
2020-02-19 03:16:27 -05:00
|
|
|
var pas page.Pages
|
|
|
|
|
2020-03-20 04:37:21 -04:00
|
|
|
m.taxonomies.WalkQuery(pageMapQuery{Prefix: prefix}, func(s string, n *contentNode) bool {
|
2020-05-21 05:25:00 -04:00
|
|
|
key := s + self
|
2020-06-15 10:33:09 -04:00
|
|
|
if tn, found := m.taxonomyEntries.Get(key); found {
|
|
|
|
vi := tn.(*contentNode).viewInfo
|
|
|
|
pas = append(pas, pageWithOrdinal{pageState: n.p, ordinal: vi.ordinal})
|
2020-02-19 03:16:27 -05:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
page.SortByDefault(pas)
|
|
|
|
|
|
|
|
return pas
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) MarshalJSON() ([]byte, error) {
|
|
|
|
return page.MarshalPageToJSON(p)
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
func (p *pageState) getPages() page.Pages {
|
|
|
|
b := p.bucket
|
|
|
|
if b == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return b.getPages()
|
|
|
|
}
|
2018-03-21 12:21:46 -04:00
|
|
|
|
2020-03-16 06:37:57 -04:00
|
|
|
func (p *pageState) getPagesRecursive() page.Pages {
|
|
|
|
b := p.bucket
|
|
|
|
if b == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return b.getPagesRecursive()
|
|
|
|
}
|
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
func (p *pageState) getPagesAndSections() page.Pages {
|
|
|
|
b := p.bucket
|
|
|
|
if b == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return b.getPagesAndSections()
|
|
|
|
}
|
|
|
|
|
2020-03-16 06:37:57 -04:00
|
|
|
func (p *pageState) RegularPagesRecursive() page.Pages {
|
|
|
|
p.regularPagesRecursiveInit.Do(func() {
|
|
|
|
var pages page.Pages
|
|
|
|
switch p.Kind() {
|
|
|
|
case page.KindSection:
|
|
|
|
pages = p.getPagesRecursive()
|
|
|
|
default:
|
|
|
|
pages = p.RegularPages()
|
|
|
|
}
|
|
|
|
p.regularPagesRecursive = pages
|
|
|
|
})
|
|
|
|
return p.regularPagesRecursive
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pageState) PagesRecursive() page.Pages {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-08-03 11:27:40 -04:00
|
|
|
func (p *pageState) RegularPages() page.Pages {
|
|
|
|
p.regularPagesInit.Do(func() {
|
2019-01-02 06:33:26 -05:00
|
|
|
var pages page.Pages
|
2018-03-21 12:21:46 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
switch p.Kind() {
|
|
|
|
case page.KindPage:
|
2020-06-16 09:43:50 -04:00
|
|
|
case page.KindSection, page.KindHome, page.KindTaxonomy:
|
2019-08-03 11:27:40 -04:00
|
|
|
pages = p.getPages()
|
2020-06-16 09:43:50 -04:00
|
|
|
case page.KindTerm:
|
2019-08-03 11:27:40 -04:00
|
|
|
all := p.Pages()
|
|
|
|
for _, p := range all {
|
|
|
|
if p.IsPage() {
|
2019-01-02 06:33:26 -05:00
|
|
|
pages = append(pages, p)
|
|
|
|
}
|
2018-03-21 12:21:46 -04:00
|
|
|
}
|
2019-08-03 11:27:40 -04:00
|
|
|
default:
|
|
|
|
pages = p.s.RegularPages()
|
|
|
|
}
|
|
|
|
|
|
|
|
p.regularPages = pages
|
|
|
|
})
|
|
|
|
|
|
|
|
return p.regularPages
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pageState) Pages() page.Pages {
|
|
|
|
p.pagesInit.Do(func() {
|
|
|
|
var pages page.Pages
|
|
|
|
|
|
|
|
switch p.Kind() {
|
|
|
|
case page.KindPage:
|
2019-09-02 11:34:02 -04:00
|
|
|
case page.KindSection, page.KindHome:
|
2019-08-03 11:27:40 -04:00
|
|
|
pages = p.getPagesAndSections()
|
2020-06-16 09:43:50 -04:00
|
|
|
case page.KindTerm:
|
2020-02-18 12:49:11 -05:00
|
|
|
pages = p.bucket.getTaxonomyEntries()
|
2020-06-16 09:43:50 -04:00
|
|
|
case page.KindTaxonomy:
|
2019-09-10 05:26:34 -04:00
|
|
|
pages = p.bucket.getTaxonomies()
|
2019-08-03 11:27:40 -04:00
|
|
|
default:
|
2019-01-02 06:33:26 -05:00
|
|
|
pages = p.s.Pages()
|
2017-06-08 14:00:05 -04:00
|
|
|
}
|
2013-10-15 09:15:52 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p.pages = pages
|
2016-08-16 16:50:15 -04:00
|
|
|
})
|
2016-09-15 22:28:13 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return p.pages
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// RawContent returns the un-rendered source content without
|
|
|
|
// any leading front matter.
|
|
|
|
func (p *pageState) RawContent() string {
|
|
|
|
if p.source.parsed == nil {
|
|
|
|
return ""
|
2018-10-30 15:24:34 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
start := p.source.posMainContent
|
2018-10-30 15:24:34 -04:00
|
|
|
if start == -1 {
|
2019-01-02 06:33:26 -05:00
|
|
|
start = 0
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return string(p.source.parsed.Input()[start:])
|
2016-08-01 17:04:44 -04:00
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
func (p *pageState) sortResources() {
|
|
|
|
sort.SliceStable(p.resources, func(i, j int) bool {
|
|
|
|
ri, rj := p.resources[i], p.resources[j]
|
|
|
|
if ri.ResourceType() < rj.ResourceType() {
|
|
|
|
return true
|
|
|
|
}
|
2014-11-28 15:16:57 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
p1, ok1 := ri.(page.Page)
|
|
|
|
p2, ok2 := rj.(page.Page)
|
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
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if ok1 != ok2 {
|
|
|
|
return ok2
|
|
|
|
}
|
2017-04-06 16:29:37 -04:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if ok1 {
|
|
|
|
return page.DefaultPageSort(p1, p2)
|
2015-01-25 06:08:02 -05:00
|
|
|
}
|
2016-10-16 13:28:21 -04:00
|
|
|
|
2020-02-19 11:37:20 -05:00
|
|
|
// Make sure not to use RelPermalink or any of the other methods that
|
|
|
|
// trigger lazy publishing.
|
|
|
|
return ri.Name() < rj.Name()
|
2019-09-10 05:26:34 -04:00
|
|
|
})
|
|
|
|
}
|
2014-10-16 20:20:09 -04:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
func (p *pageState) Resources() resource.Resources {
|
|
|
|
p.resourcesInit.Do(func() {
|
|
|
|
p.sortResources()
|
2019-01-02 06:33:26 -05:00
|
|
|
if len(p.m.resourcesMetadata) > 0 {
|
|
|
|
resources.AssignMetadata(p.m.resourcesMetadata, p.resources...)
|
2019-09-10 05:26:34 -04:00
|
|
|
p.sortResources()
|
2015-09-03 06:22:20 -04:00
|
|
|
}
|
2016-08-17 07:41:48 -04:00
|
|
|
})
|
2019-01-02 06:33:26 -05:00
|
|
|
return p.resources
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) HasShortcode(name string) bool {
|
2017-07-17 17:20:13 -04:00
|
|
|
if p.shortcodeState == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.shortcodeState.nameSet[name]
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) Site() page.Site {
|
2019-09-10 05:26:34 -04:00
|
|
|
return p.s.Info
|
2016-07-25 16:22:09 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) String() string {
|
|
|
|
if sourceRef := p.sourceRef(); sourceRef != "" {
|
|
|
|
return fmt.Sprintf("Page(%s)", sourceRef)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("Page(%q)", p.Title())
|
2016-08-09 08:26:55 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// IsTranslated returns whether this content file is translated to
|
|
|
|
// other language(s).
|
|
|
|
func (p *pageState) IsTranslated() bool {
|
|
|
|
p.s.h.init.translations.Do()
|
|
|
|
return len(p.translations) > 0
|
2016-07-25 16:22:09 -04:00
|
|
|
}
|
|
|
|
|
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.
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) TranslationKey() string {
|
|
|
|
p.translationKeyInit.Do(func() {
|
|
|
|
if p.m.translationKey != "" {
|
|
|
|
p.translationKey = p.Kind() + "/" + p.m.translationKey
|
2019-03-25 13:18:34 -04:00
|
|
|
} else if p.IsPage() && !p.File().IsZero() {
|
2019-01-02 06:33:26 -05:00
|
|
|
p.translationKey = path.Join(p.Kind(), filepath.ToSlash(p.File().Dir()), p.File().TranslationBaseName())
|
|
|
|
} else if p.IsNode() {
|
|
|
|
p.translationKey = path.Join(p.Kind(), p.SectionsPath())
|
|
|
|
}
|
|
|
|
})
|
2018-01-15 14:40:39 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return p.translationKey
|
: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
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// AllTranslations returns all translations, including the current Page.
|
|
|
|
func (p *pageState) AllTranslations() page.Pages {
|
|
|
|
p.s.h.init.translations.Do()
|
|
|
|
return p.allTranslations
|
2018-11-06 04:04:37 -05:00
|
|
|
}
|
2018-05-08 04:10:13 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Translations returns the translations excluding the current Page.
|
|
|
|
func (p *pageState) Translations() page.Pages {
|
|
|
|
p.s.h.init.translations.Do()
|
|
|
|
return p.translations
|
2018-05-08 04:10:13 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (ps *pageState) initCommonProviders(pp pagePaths) error {
|
|
|
|
if ps.IsPage() {
|
|
|
|
ps.posNextPrev = &nextPrev{init: ps.s.init.prevNext}
|
|
|
|
ps.posNextPrevSection = &nextPrev{init: ps.s.init.prevNextInSection}
|
|
|
|
ps.InSectionPositioner = newPagePositionInSection(ps.posNextPrevSection)
|
|
|
|
ps.Positioner = newPagePosition(ps.posNextPrev)
|
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
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
ps.OutputFormatsProvider = pp
|
|
|
|
ps.targetPathDescriptor = pp.targetPathDescriptor
|
|
|
|
ps.RefProvider = newPageRef(ps)
|
2019-09-10 05:26:34 -04:00
|
|
|
ps.SitesProvider = ps.s.Info
|
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
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) getLayoutDescriptor() output.LayoutDescriptor {
|
|
|
|
p.layoutDescriptorInit.Do(func() {
|
|
|
|
var section string
|
|
|
|
sections := p.SectionsEntries()
|
2018-03-11 13:59:11 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
switch p.Kind() {
|
|
|
|
case page.KindSection:
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
if len(sections) > 0 {
|
|
|
|
section = sections[0]
|
|
|
|
}
|
2020-06-16 09:43:50 -04:00
|
|
|
case page.KindTaxonomy, page.KindTerm:
|
2019-09-10 05:26:34 -04:00
|
|
|
b := p.getTreeRef().n
|
|
|
|
section = b.viewInfo.name.singular
|
2019-01-02 06:33:26 -05:00
|
|
|
default:
|
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
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p.layoutDescriptor = output.LayoutDescriptor{
|
|
|
|
Kind: p.Kind(),
|
|
|
|
Type: p.Type(),
|
|
|
|
Lang: p.Language().Lang,
|
|
|
|
Layout: p.Layout(),
|
|
|
|
Section: section,
|
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
|
|
|
}
|
2019-01-02 06:33:26 -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
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return p.layoutDescriptor
|
|
|
|
}
|
2018-01-15 14:40:39 -05:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
func (p *pageState) resolveTemplate(layouts ...string) (tpl.Template, bool, error) {
|
2019-01-02 06:33:26 -05:00
|
|
|
f := p.outputFormat()
|
2018-01-15 14:40:39 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if len(layouts) == 0 {
|
|
|
|
selfLayout := p.selfLayoutForOutput(f)
|
|
|
|
if selfLayout != "" {
|
2020-01-15 09:59:56 -05:00
|
|
|
templ, found := p.s.Tmpl().Lookup(selfLayout)
|
|
|
|
return templ, found, nil
|
2014-01-29 17:50:31 -05:00
|
|
|
}
|
|
|
|
}
|
2015-05-14 16:06:36 -04:00
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
d := p.getLayoutDescriptor()
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
if len(layouts) > 0 {
|
2020-01-15 09:59:56 -05:00
|
|
|
d.Layout = layouts[0]
|
|
|
|
d.LayoutOverride = true
|
2018-05-04 20:17:16 -04:00
|
|
|
}
|
|
|
|
|
2020-01-15 09:59:56 -05:00
|
|
|
return p.s.Tmpl().LookupLayout(d, f)
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is serialized
|
2019-04-10 04:11:51 -04:00
|
|
|
func (p *pageState) initOutputFormat(isRenderingSite bool, idx int) error {
|
|
|
|
if err := p.shiftToOutputFormat(isRenderingSite, idx); err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
return err
|
2015-08-02 02:02:20 -04:00
|
|
|
}
|
|
|
|
|
2014-01-29 17:50:31 -05:00
|
|
|
return nil
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Must be run after the site section tree etc. is built and ready.
|
|
|
|
func (p *pageState) initPage() error {
|
|
|
|
if _, err := p.init.Do(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2017-12-29 02:58:38 -05:00
|
|
|
}
|
|
|
|
|
2019-04-15 06:06:12 -04:00
|
|
|
func (p *pageState) renderResources() (err error) {
|
|
|
|
p.resourcesPublishInit.Do(func() {
|
|
|
|
var toBeDeleted []int
|
|
|
|
|
|
|
|
for i, r := range p.Resources() {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
2019-04-15 06:06:12 -04:00
|
|
|
if _, ok := r.(page.Page); ok {
|
|
|
|
// Pages gets rendered with the owning page but we count them here.
|
|
|
|
p.s.PathSpec.ProcessingStats.Incr(&p.s.PathSpec.ProcessingStats.Pages)
|
|
|
|
continue
|
|
|
|
}
|
2014-01-29 17:50:31 -05:00
|
|
|
|
2019-04-15 06:06:12 -04:00
|
|
|
src, ok := r.(resource.Source)
|
|
|
|
if !ok {
|
|
|
|
err = errors.Errorf("Resource %T does not support resource.Source", src)
|
|
|
|
return
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2019-04-15 06:06:12 -04:00
|
|
|
if err := src.Publish(); err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
// The resource has been deleted from the file system.
|
|
|
|
// This should be extremely rare, but can happen on live reload in server
|
|
|
|
// mode when the same resource is member of different page bundles.
|
|
|
|
toBeDeleted = append(toBeDeleted, i)
|
|
|
|
} else {
|
2020-10-21 05:17:48 -04:00
|
|
|
p.s.Log.Errorf("Failed to publish Resource for page %q: %s", p.pathOrTitle(), err)
|
2019-04-15 06:06:12 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
} else {
|
2019-04-15 06:06:12 -04:00
|
|
|
p.s.PathSpec.ProcessingStats.Incr(&p.s.PathSpec.ProcessingStats.Files)
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2015-05-31 14:30:53 -04:00
|
|
|
}
|
2015-01-24 06:44:35 -05:00
|
|
|
|
2019-04-15 06:06:12 -04:00
|
|
|
for _, i := range toBeDeleted {
|
|
|
|
p.deleteResource(i)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
2013-07-04 11:32:55 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) deleteResource(i int) {
|
|
|
|
p.resources = append(p.resources[:i], p.resources[i+1:]...)
|
|
|
|
}
|
2015-01-06 12:11:06 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) getTargetPaths() page.TargetPaths {
|
|
|
|
return p.targetPaths()
|
|
|
|
}
|
2017-02-20 03:33:35 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) setTranslations(pages page.Pages) {
|
|
|
|
p.allTranslations = pages
|
|
|
|
page.SortByLanguage(p.allTranslations)
|
|
|
|
translations := make(page.Pages, 0)
|
|
|
|
for _, t := range p.allTranslations {
|
|
|
|
if !t.Eq(p) {
|
|
|
|
translations = append(translations, t)
|
2017-02-20 03:33:35 -05:00
|
|
|
}
|
2015-01-06 12:11:06 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
p.translations = translations
|
|
|
|
}
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) AlternativeOutputFormats() page.OutputFormats {
|
|
|
|
f := p.outputFormat()
|
|
|
|
var o page.OutputFormats
|
|
|
|
for _, of := range p.OutputFormats() {
|
|
|
|
if of.Format.NotAlternative || of.Format.Name == f.Name {
|
|
|
|
continue
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
o = append(o, of)
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return o
|
|
|
|
}
|
2016-11-13 08:27:10 -05:00
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
type renderStringOpts struct {
|
|
|
|
Display string
|
|
|
|
Markup string
|
|
|
|
}
|
|
|
|
|
2020-12-16 06:11:32 -05:00
|
|
|
var defaultRenderStringOpts = renderStringOpts{
|
2019-11-27 07:42:36 -05:00
|
|
|
Display: "inline",
|
|
|
|
Markup: "", // Will inherit the page's value when not set.
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pageState) addDependency(dep identity.Provider) {
|
|
|
|
if !p.s.running() || p.pageOutput.cp == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
p.pageOutput.cp.dependencyTracker.Add(dep)
|
|
|
|
}
|
|
|
|
|
2019-12-20 02:11:36 -05:00
|
|
|
// wrapError adds some more context to the given error if possible/needed
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) wrapError(err error) error {
|
2019-12-20 02:11:36 -05:00
|
|
|
if _, ok := err.(*herrors.ErrorWithFileContext); ok {
|
|
|
|
// Preserve the first file context.
|
|
|
|
return err
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
var filename string
|
2019-03-25 13:18:34 -04:00
|
|
|
if !p.File().IsZero() {
|
2019-01-02 06:33:26 -05:00
|
|
|
filename = p.File().Filename()
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
err, _ = herrors.WithFileContextForFile(
|
|
|
|
err,
|
|
|
|
filename,
|
|
|
|
filename,
|
|
|
|
p.s.SourceSpec.Fs.Source,
|
|
|
|
herrors.SimpleLineMatcher)
|
2016-11-13 08:27:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return err
|
|
|
|
}
|
2016-11-13 08:27:10 -05:00
|
|
|
|
2019-08-16 09:55:03 -04:00
|
|
|
func (p *pageState) getContentConverter() converter.Converter {
|
2020-02-18 08:00:58 -05:00
|
|
|
var err error
|
|
|
|
p.m.contentConverterInit.Do(func() {
|
|
|
|
markup := p.m.markup
|
|
|
|
if markup == "html" {
|
|
|
|
// Only used for shortcode inner content.
|
|
|
|
markup = "markdown"
|
|
|
|
}
|
|
|
|
p.m.contentConverter, err = p.m.newContentConverter(p, markup, p.m.renderingConfigOverrides)
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2020-10-21 05:17:48 -04:00
|
|
|
p.s.Log.Errorln("Failed to create content converter:", err)
|
2020-02-18 08:00:58 -05:00
|
|
|
}
|
2019-08-16 09:55:03 -04:00
|
|
|
return p.m.contentConverter
|
|
|
|
}
|
|
|
|
|
2019-08-09 04:05:22 -04:00
|
|
|
func (p *pageState) mapContent(bucket *pagesMapBucket, meta *pageMeta) error {
|
2019-01-02 06:33:26 -05:00
|
|
|
s := p.shortcodeState
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
rn := &pageContentMap{
|
2022-03-17 17:03:27 -04:00
|
|
|
items: make([]any, 0, 20),
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
iter := p.source.parsed.Iterator()
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
fail := func(err error, i pageparser.Item) error {
|
|
|
|
return p.parseError(err, iter.Input(), i.Pos)
|
|
|
|
}
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// the parser is guaranteed to return items in proper order or fail, so …
|
|
|
|
// … it's safe to keep some "global" state
|
|
|
|
var currShortcode shortcode
|
|
|
|
var ordinal int
|
2019-09-10 05:26:34 -04:00
|
|
|
var frontMatterSet bool
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
Loop:
|
|
|
|
for {
|
|
|
|
it := iter.Next()
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
switch {
|
|
|
|
case it.Type == pageparser.TypeIgnore:
|
|
|
|
case it.IsFrontMatter():
|
2019-09-10 05:26:34 -04:00
|
|
|
f := pageparser.FormatFromFrontMatterType(it.Type)
|
2019-01-02 06:33:26 -05:00
|
|
|
m, err := metadecoders.Default.UnmarshalToMap(it.Val, f)
|
2014-04-23 02:59:19 -04:00
|
|
|
if err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
if fe, ok := err.(herrors.FileError); ok {
|
|
|
|
return herrors.ToFileErrorWithOffset(fe, iter.LineNumber()-1)
|
|
|
|
} else {
|
|
|
|
return err
|
2015-02-04 15:27:27 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-08-09 04:05:22 -04:00
|
|
|
if err := meta.setMetadata(bucket, p, m); err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
return err
|
2015-02-04 15:27:27 -05:00
|
|
|
}
|
2020-02-21 03:02:07 -05:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
frontMatterSet = true
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
next := iter.Peek()
|
|
|
|
if !next.IsDone() {
|
|
|
|
p.source.posMainContent = next.Pos
|
|
|
|
}
|
2014-04-23 02:59:19 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if !p.s.shouldBuild(p) {
|
|
|
|
// Nothing more to do.
|
|
|
|
return nil
|
|
|
|
}
|
2017-05-06 14:15:28 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
case it.Type == pageparser.TypeLeadSummaryDivider:
|
|
|
|
posBody := -1
|
|
|
|
f := func(item pageparser.Item) bool {
|
|
|
|
if posBody == -1 && !item.IsDone() {
|
|
|
|
posBody = item.Pos
|
|
|
|
}
|
2015-07-02 09:32:57 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if item.IsNonWhitespace() {
|
|
|
|
p.truncated = true
|
2014-05-01 13:21:37 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Done
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
iter.PeekWalk(f)
|
2018-07-17 05:18:29 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p.source.posSummaryEnd = it.Pos
|
|
|
|
p.source.posBodyStart = posBody
|
|
|
|
p.source.hasSummaryDivider = true
|
2018-07-17 05:18:29 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if meta.markup != "html" {
|
|
|
|
// The content will be rendered by Blackfriday or similar,
|
|
|
|
// and we need to track the summary.
|
|
|
|
rn.AddReplacement(internalSummaryDividerPre, it)
|
|
|
|
}
|
2018-05-29 21:35:27 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Handle shortcode
|
|
|
|
case it.IsLeftShortcodeDelim():
|
|
|
|
// let extractShortcode handle left delim (will do so recursively)
|
|
|
|
iter.Backup()
|
2016-10-31 05:23:01 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
currShortcode, err := s.extractShortcode(ordinal, 0, iter)
|
2016-10-31 05:23:01 -04:00
|
|
|
if err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
return fail(errors.Wrap(err, "failed to extract shortcode"), it)
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
currShortcode.pos = it.Pos
|
|
|
|
currShortcode.length = iter.Current().Pos - it.Pos
|
|
|
|
if currShortcode.placeholder == "" {
|
|
|
|
currShortcode.placeholder = createShortcodePlaceholder("s", currShortcode.ordinal)
|
2016-12-26 13:30:57 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if currShortcode.name != "" {
|
|
|
|
s.nameSet[currShortcode.name] = true
|
2017-03-05 15:24:14 -05:00
|
|
|
}
|
2016-10-31 14:53:33 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if currShortcode.params == nil {
|
|
|
|
var s []string
|
|
|
|
currShortcode.params = s
|
|
|
|
}
|
2016-11-11 03:19:16 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
currShortcode.placeholder = createShortcodePlaceholder("s", ordinal)
|
|
|
|
ordinal++
|
|
|
|
s.shortcodes = append(s.shortcodes, currShortcode)
|
2016-11-11 05:35:55 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
rn.AddShortcode(currShortcode)
|
2016-10-31 05:23:01 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
case it.Type == pageparser.TypeEmoji:
|
|
|
|
if emoji := helpers.Emoji(it.ValStr()); emoji != nil {
|
|
|
|
rn.AddReplacement(emoji, it)
|
|
|
|
} else {
|
|
|
|
rn.AddBytes(it)
|
|
|
|
}
|
|
|
|
case it.IsEOF():
|
|
|
|
break Loop
|
|
|
|
case it.IsError():
|
|
|
|
err := fail(errors.WithStack(errors.New(it.ValStr())), it)
|
|
|
|
currShortcode.err = err
|
|
|
|
return err
|
2016-11-11 05:35:55 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
default:
|
|
|
|
rn.AddBytes(it)
|
2016-11-11 05:35:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if !frontMatterSet {
|
|
|
|
// Page content without front matter. Assign default front matter from
|
|
|
|
// cascades etc.
|
|
|
|
if err := meta.setMetadata(bucket, p, nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p.cmap = rn
|
2016-11-11 05:35:55 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return nil
|
|
|
|
}
|
2016-11-11 05:35:55 -05:00
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func (p *pageState) errorf(err error, format string, a ...any) error {
|
2019-01-02 06:33:26 -05:00
|
|
|
if herrors.UnwrapErrorWithFileContext(err) != nil {
|
|
|
|
// More isn't always better.
|
|
|
|
return err
|
|
|
|
}
|
2022-03-17 17:03:27 -04:00
|
|
|
args := append([]any{p.Language().Lang, p.pathOrTitle()}, a...)
|
2019-01-02 06:33:26 -05:00
|
|
|
format = "[%s] page %q: " + format
|
|
|
|
if err == nil {
|
|
|
|
errors.Errorf(format, args...)
|
|
|
|
return fmt.Errorf(format, args...)
|
2016-11-11 05:35:55 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return errors.Wrapf(err, format, args...)
|
2016-11-11 05:35:55 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) outputFormat() (f output.Format) {
|
|
|
|
if p.pageOutput == nil {
|
|
|
|
panic("no pageOutput")
|
2018-05-08 04:10:13 -04:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
return p.pageOutput.f
|
2016-10-31 05:23:01 -04:00
|
|
|
}
|
2016-11-13 08:27:10 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) parseError(err error, input []byte, offset int) error {
|
|
|
|
if herrors.UnwrapFileError(err) != nil {
|
|
|
|
// Use the most specific location.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pos := p.posFromInput(input, offset)
|
|
|
|
return herrors.NewFileError("md", -1, pos.LineNumber, pos.ColumnNumber, err)
|
2018-05-29 21:35:27 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) pathOrTitle() string {
|
2019-03-25 13:18:34 -04:00
|
|
|
if !p.File().IsZero() {
|
2019-01-02 06:33:26 -05:00
|
|
|
return p.File().Filename()
|
2018-05-25 19:59:58 -04:00
|
|
|
}
|
2016-11-13 08:27:10 -05:00
|
|
|
|
2022-01-04 07:07:10 -05:00
|
|
|
if p.Pathc() != "" {
|
|
|
|
return p.Pathc()
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
return p.Title()
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) posFromPage(offset int) text.Position {
|
|
|
|
return p.posFromInput(p.source.parsed.Input(), offset)
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) posFromInput(input []byte, offset int) text.Position {
|
2022-03-08 14:10:19 -05:00
|
|
|
if offset < 0 {
|
|
|
|
return text.Position{
|
|
|
|
Filename: p.pathOrTitle(),
|
|
|
|
}
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
lf := []byte("\n")
|
|
|
|
input = input[:offset]
|
|
|
|
lineNumber := bytes.Count(input, lf) + 1
|
|
|
|
endOfLastLine := bytes.LastIndex(input, lf)
|
|
|
|
|
|
|
|
return text.Position{
|
|
|
|
Filename: p.pathOrTitle(),
|
|
|
|
LineNumber: lineNumber,
|
|
|
|
ColumnNumber: offset - endOfLastLine,
|
|
|
|
Offset: offset,
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (p *pageState) posOffset(offset int) text.Position {
|
|
|
|
return p.posFromInput(p.source.parsed.Input(), offset)
|
|
|
|
}
|
2016-12-23 03:52:05 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// shiftToOutputFormat is serialized. The output format idx refers to the
|
|
|
|
// full set of output formats for all sites.
|
2019-04-10 04:11:51 -04:00
|
|
|
func (p *pageState) shiftToOutputFormat(isRenderingSite bool, idx int) error {
|
2019-01-02 06:33:26 -05:00
|
|
|
if err := p.initPage(); err != nil {
|
|
|
|
return err
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
if len(p.pageOutputs) == 1 {
|
|
|
|
idx = 0
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
p.pageOutput = p.pageOutputs[idx]
|
|
|
|
if p.pageOutput == nil {
|
|
|
|
panic(fmt.Sprintf("pageOutput is nil for output idx %d", idx))
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-04-10 04:11:51 -04:00
|
|
|
// Reset any built paginator. This will trigger when re-rendering pages in
|
|
|
|
// server mode.
|
|
|
|
if isRenderingSite && p.pageOutput.paginator != nil && p.pageOutput.paginator.current != nil {
|
|
|
|
p.pageOutput.paginator.reset()
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
if isRenderingSite {
|
|
|
|
cp := p.pageOutput.cp
|
2022-02-17 07:04:00 -05:00
|
|
|
if cp == nil && p.reusePageOutputContent() {
|
2019-11-27 07:42:36 -05:00
|
|
|
// Look for content to reuse.
|
|
|
|
for i := 0; i < len(p.pageOutputs); i++ {
|
|
|
|
if i == idx {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
po := p.pageOutputs[i]
|
|
|
|
|
2022-02-17 07:04:00 -05:00
|
|
|
if po.cp != nil {
|
2019-11-27 07:42:36 -05:00
|
|
|
cp = po.cp
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if cp == nil {
|
|
|
|
var err error
|
|
|
|
cp, err = newPageContentOutput(p, p.pageOutput)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
2019-11-27 07:42:36 -05:00
|
|
|
p.pageOutput.initContentProvider(cp)
|
2022-01-11 11:32:58 -05:00
|
|
|
} else {
|
|
|
|
// We attempt to assign pageContentOutputs while preparing each site
|
|
|
|
// for rendering and before rendering each site. This lets us share
|
|
|
|
// content between page outputs to conserve resources. But if a template
|
|
|
|
// unexpectedly calls a method of a ContentProvider that is not yet
|
|
|
|
// initialized, we assign a LazyContentProvider that performs the
|
|
|
|
// initialization just in time.
|
|
|
|
if lcp, ok := (p.pageOutput.ContentProvider.(*page.LazyContentProvider)); ok {
|
|
|
|
lcp.Reset()
|
|
|
|
} else {
|
2022-01-27 03:46:51 -05:00
|
|
|
lcp = page.NewLazyContentProvider(func() (page.OutputFormatContentProvider, error) {
|
2022-01-11 11:32:58 -05:00
|
|
|
cp, err := newPageContentOutput(p, p.pageOutput)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return cp, nil
|
|
|
|
})
|
2022-01-27 03:46:51 -05:00
|
|
|
p.pageOutput.ContentProvider = lcp
|
|
|
|
p.pageOutput.TableOfContentsProvider = lcp
|
|
|
|
p.pageOutput.PageRenderProvider = lcp
|
2022-01-11 11:32:58 -05:00
|
|
|
}
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return nil
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// sourceRef returns the reference used by GetPage and ref/relref shortcodes to refer to
|
|
|
|
// this page. It is prefixed with a "/".
|
|
|
|
//
|
|
|
|
// 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.
|
2020-12-16 06:11:32 -05:00
|
|
|
// For pages that do not (sections without content page etc.), it returns the
|
2019-01-02 06:33:26 -05:00
|
|
|
// virtual path, consistent with where you would add a source file.
|
|
|
|
func (p *pageState) sourceRef() string {
|
2019-03-25 13:18:34 -04:00
|
|
|
if !p.File().IsZero() {
|
2019-01-02 06:33:26 -05:00
|
|
|
sourcePath := p.File().Path()
|
|
|
|
if sourcePath != "" {
|
|
|
|
return "/" + filepath.ToSlash(sourcePath)
|
|
|
|
}
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
if len(p.SectionsEntries()) > 0 {
|
|
|
|
// no backing file, return the virtual source path
|
|
|
|
return "/" + p.SectionsPath()
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return ""
|
2016-11-13 08:27:10 -05:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func (s *Site) sectionsFromFile(fi source.File) []string {
|
|
|
|
dirname := fi.Dir()
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
dirname = strings.Trim(dirname, helpers.FilePathSeparator)
|
|
|
|
if dirname == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
parts := strings.Split(dirname, helpers.FilePathSeparator)
|
|
|
|
|
|
|
|
if fii, ok := fi.(*fileInfo); ok {
|
2021-07-13 05:41:02 -04:00
|
|
|
if len(parts) > 0 && fii.FileInfo().Meta().Classifier == files.ContentClassLeaf {
|
2019-01-02 06:33:26 -05:00
|
|
|
// my-section/mybundle/index.md => my-section
|
|
|
|
return parts[:len(parts)-1]
|
|
|
|
}
|
2017-03-26 13:34:30 -04:00
|
|
|
}
|
2018-09-24 18:06:29 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
return parts
|
2018-09-24 18:06:29 -04:00
|
|
|
}
|
2020-06-15 10:33:09 -04:00
|
|
|
|
|
|
|
var (
|
|
|
|
_ page.Page = (*pageWithOrdinal)(nil)
|
|
|
|
_ collections.Order = (*pageWithOrdinal)(nil)
|
|
|
|
_ pageWrapper = (*pageWithOrdinal)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type pageWithOrdinal struct {
|
|
|
|
ordinal int
|
|
|
|
*pageState
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p pageWithOrdinal) Ordinal() int {
|
|
|
|
return p.ordinal
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p pageWithOrdinal) page() page.Page {
|
|
|
|
return p.pageState
|
|
|
|
}
|