2016-11-03 19:34:25 -04:00
|
|
|
// Copyright 2016 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2017-05-25 05:32:02 -04:00
|
|
|
import (
|
|
|
|
"path"
|
2017-05-25 14:13:03 -04:00
|
|
|
"path/filepath"
|
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/cache"
|
2017-05-25 05:32:02 -04:00
|
|
|
)
|
|
|
|
|
2016-11-11 03:01:47 -05:00
|
|
|
// PageCollections contains the page collections for a site.
|
2016-11-03 19:34:25 -04:00
|
|
|
type PageCollections struct {
|
2016-11-11 03:01:47 -05:00
|
|
|
// Includes only pages of all types, and only pages in the current language.
|
2016-11-03 19:34:25 -04:00
|
|
|
Pages Pages
|
|
|
|
|
|
|
|
// Includes all pages in all languages, including the current one.
|
2017-02-02 16:25:42 -05:00
|
|
|
// Includes pages of all types.
|
2016-11-03 19:34:25 -04:00
|
|
|
AllPages Pages
|
|
|
|
|
2016-11-11 03:01:47 -05:00
|
|
|
// A convenience cache for the traditional index types, taxonomies, home page etc.
|
|
|
|
// This is for the current language only.
|
|
|
|
indexPages Pages
|
2016-11-03 19:34:25 -04:00
|
|
|
|
2016-11-11 03:01:47 -05:00
|
|
|
// A convenience cache for the regular pages.
|
2016-11-03 19:34:25 -04:00
|
|
|
// This is for the current language only.
|
2016-11-13 08:27:10 -05:00
|
|
|
RegularPages Pages
|
2016-11-03 19:34:25 -04:00
|
|
|
|
2016-11-16 15:06:10 -05:00
|
|
|
// A convenience cache for the all the regular pages.
|
|
|
|
AllRegularPages Pages
|
|
|
|
|
2016-11-03 19:34:25 -04:00
|
|
|
// Includes absolute all pages (of all types), including drafts etc.
|
|
|
|
rawAllPages Pages
|
2017-05-25 14:13:03 -04:00
|
|
|
|
|
|
|
pageCache *cache.PartitionedLazyCache
|
2016-11-03 19:34:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PageCollections) refreshPageCaches() {
|
2016-11-16 11:52:03 -05:00
|
|
|
c.indexPages = c.findPagesByKindNotIn(KindPage, c.Pages)
|
|
|
|
c.RegularPages = c.findPagesByKindIn(KindPage, c.Pages)
|
2016-11-16 15:06:10 -05:00
|
|
|
c.AllRegularPages = c.findPagesByKindIn(KindPage, c.AllPages)
|
2016-11-07 14:24:37 -05:00
|
|
|
|
2018-01-17 13:26:34 -05:00
|
|
|
var s *Site
|
|
|
|
|
|
|
|
if len(c.Pages) > 0 {
|
|
|
|
s = c.Pages[0].s
|
|
|
|
}
|
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
cacheLoader := func(kind string) func() (map[string]interface{}, error) {
|
|
|
|
return func() (map[string]interface{}, error) {
|
|
|
|
cache := make(map[string]interface{})
|
|
|
|
switch kind {
|
|
|
|
case KindPage:
|
|
|
|
// Note that we deliberately use the pages from all sites
|
|
|
|
// in this cache, as we intend to use this in the ref and relref
|
|
|
|
// shortcodes. If the user says "sect/doc1.en.md", he/she knows
|
|
|
|
// what he/she is looking for.
|
|
|
|
for _, p := range c.AllRegularPages {
|
|
|
|
cache[filepath.ToSlash(p.Source.Path())] = p
|
2017-05-26 03:12:19 -04:00
|
|
|
// Ref/Relref supports this potentially ambiguous lookup.
|
|
|
|
cache[p.Source.LogicalName()] = p
|
2018-01-17 13:26:34 -05:00
|
|
|
|
|
|
|
if s != nil && p.s == s {
|
|
|
|
// We need a way to get to the current language version.
|
|
|
|
pathWithNoExtensions := path.Join(filepath.ToSlash(p.Source.Dir()), p.Source.TranslationBaseName())
|
|
|
|
cache[pathWithNoExtensions] = p
|
|
|
|
}
|
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
for _, p := range c.indexPages {
|
|
|
|
key := path.Join(p.sections...)
|
|
|
|
cache[key] = p
|
|
|
|
}
|
2017-05-25 05:32:02 -04:00
|
|
|
}
|
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
return cache, nil
|
2016-11-07 14:24:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 03:39:43 -05:00
|
|
|
partitions := make([]cache.Partition, len(allKindsInPages))
|
2017-05-22 18:20:31 -04:00
|
|
|
|
2017-11-11 03:39:43 -05:00
|
|
|
for i, kind := range allKindsInPages {
|
|
|
|
partitions[i] = cache.Partition{Key: kind, Load: cacheLoader(kind)}
|
2017-05-25 14:13:03 -04:00
|
|
|
}
|
2017-05-22 18:20:31 -04:00
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
c.pageCache = cache.NewPartitionedLazyCache(partitions...)
|
|
|
|
}
|
2017-05-25 05:32:02 -04:00
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
func newPageCollections() *PageCollections {
|
|
|
|
return &PageCollections{}
|
2017-05-25 05:32:02 -04:00
|
|
|
}
|
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
func newPageCollectionsFromPages(pages Pages) *PageCollections {
|
|
|
|
return &PageCollections{rawAllPages: pages}
|
|
|
|
}
|
2017-05-22 18:20:31 -04:00
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
func (c *PageCollections) getPage(typ string, sections ...string) *Page {
|
|
|
|
var key string
|
|
|
|
if len(sections) == 1 {
|
|
|
|
key = filepath.ToSlash(sections[0])
|
2017-05-22 18:20:31 -04:00
|
|
|
} else {
|
2017-05-25 14:13:03 -04:00
|
|
|
key = path.Join(sections...)
|
2017-05-22 18:20:31 -04:00
|
|
|
}
|
|
|
|
|
2017-05-25 14:13:03 -04:00
|
|
|
p, _ := c.pageCache.Get(typ, key)
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return p.(*Page)
|
2017-05-22 18:20:31 -04:00
|
|
|
|
2016-11-07 14:24:37 -05:00
|
|
|
}
|
|
|
|
|
2016-11-16 11:52:03 -05:00
|
|
|
func (*PageCollections) findPagesByKindIn(kind string, inPages Pages) Pages {
|
2016-11-03 19:34:25 -04:00
|
|
|
var pages Pages
|
|
|
|
for _, p := range inPages {
|
2016-11-16 11:52:03 -05:00
|
|
|
if p.Kind == kind {
|
2016-11-03 19:34:25 -04:00
|
|
|
pages = append(pages, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pages
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:52:03 -05:00
|
|
|
func (*PageCollections) findPagesByKindNotIn(kind string, inPages Pages) Pages {
|
2016-11-03 19:34:25 -04:00
|
|
|
var pages Pages
|
|
|
|
for _, p := range inPages {
|
2016-11-16 11:52:03 -05:00
|
|
|
if p.Kind != kind {
|
2016-11-03 19:34:25 -04:00
|
|
|
pages = append(pages, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pages
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:52:03 -05:00
|
|
|
func (c *PageCollections) findPagesByKind(kind string) Pages {
|
|
|
|
return c.findPagesByKindIn(kind, c.Pages)
|
2016-11-03 19:34:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PageCollections) addPage(page *Page) {
|
|
|
|
c.rawAllPages = append(c.rawAllPages, page)
|
|
|
|
}
|
|
|
|
|
2017-06-08 14:00:05 -04:00
|
|
|
// When we get a REMOVE event we're not always getting all the individual files,
|
|
|
|
// so we need to remove all below a given path.
|
|
|
|
func (c *PageCollections) removePageByPathPrefix(path string) {
|
|
|
|
for {
|
2017-06-08 16:32:01 -04:00
|
|
|
i := c.rawAllPages.findFirstPagePosByFilePathPrefix(path)
|
2017-06-08 14:00:05 -04:00
|
|
|
if i == -1 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
c.rawAllPages = append(c.rawAllPages[:i], c.rawAllPages[i+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-03 19:34:25 -04:00
|
|
|
func (c *PageCollections) removePageByPath(path string) {
|
2017-06-08 16:32:01 -04:00
|
|
|
if i := c.rawAllPages.findPagePosByFilePath(path); i >= 0 {
|
: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
|
|
|
c.clearResourceCacheForPage(c.rawAllPages[i])
|
2016-11-03 19:34:25 -04:00
|
|
|
c.rawAllPages = append(c.rawAllPages[:i], c.rawAllPages[i+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
|
|
|
|
2016-11-03 19:34:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PageCollections) removePage(page *Page) {
|
2017-06-08 16:32:01 -04:00
|
|
|
if i := c.rawAllPages.findPagePos(page); i >= 0 {
|
: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
|
|
|
c.clearResourceCacheForPage(c.rawAllPages[i])
|
2016-11-03 19:34:25 -04:00
|
|
|
c.rawAllPages = append(c.rawAllPages[:i], c.rawAllPages[i+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
|
|
|
|
2016-11-03 19:34:25 -04:00
|
|
|
}
|
|
|
|
|
2017-03-10 14:54:50 -05:00
|
|
|
func (c *PageCollections) findPagesByShortcode(shortcode string) Pages {
|
|
|
|
var pages Pages
|
|
|
|
|
|
|
|
for _, p := range c.rawAllPages {
|
|
|
|
if p.shortcodeState != nil {
|
|
|
|
if _, ok := p.shortcodeState.nameSet[shortcode]; ok {
|
|
|
|
pages = append(pages, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pages
|
|
|
|
}
|
|
|
|
|
2016-11-03 19:34:25 -04:00
|
|
|
func (c *PageCollections) replacePage(page *Page) {
|
|
|
|
// will find existing page that matches filepath and remove it
|
|
|
|
c.removePage(page)
|
|
|
|
c.addPage(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
|
|
|
|
|
|
|
func (c *PageCollections) clearResourceCacheForPage(page *Page) {
|
|
|
|
if len(page.Resources) > 0 {
|
|
|
|
first := page.Resources[0]
|
|
|
|
dir := path.Dir(first.RelPermalink())
|
|
|
|
// This is done to keep the memory usage in check when doing live reloads.
|
|
|
|
page.s.resourceSpec.DeleteCacheByPrefix(dir)
|
|
|
|
}
|
|
|
|
}
|