summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-01-02 12:33:26 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-03-23 18:51:22 +0100
commit597e418cb02883418f2cebb41400e8e61413f651 (patch)
tree177ad9c540b2583b6dab138c9f0490d28989c7f7 /hugolib
parent44f5c1c14cb1f42cc5f01739c289e9cfc83602af (diff)
Make Page an interface
The main motivation of this commit is to add a `page.Page` interface to replace the very file-oriented `hugolib.Page` struct. This is all a preparation step for issue #5074, "pages from other data sources". But this also fixes a set of annoying limitations, especially related to custom output formats, and shortcodes. Most notable changes: * The inner content of shortcodes using the `{{%` as the outer-most delimiter will now be sent to the content renderer, e.g. Blackfriday. This means that any markdown will partake in the global ToC and footnote context etc. * The Custom Output formats are now "fully virtualized". This removes many of the current limitations. * The taxonomy list type now has a reference to the `Page` object. This improves the taxonomy template `.Title` situation and make common template constructs much simpler. See #5074 Fixes #5763 Fixes #5758 Fixes #5090 Fixes #5204 Fixes #4695 Fixes #5607 Fixes #5707 Fixes #5719 Fixes #3113 Fixes #5706 Fixes #5767 Fixes #5723 Fixes #5769 Fixes #5770 Fixes #5771 Fixes #5759 Fixes #5776 Fixes #5777 Fixes #5778
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/alias.go29
-rw-r--r--hugolib/alias_test.go4
-rw-r--r--hugolib/author.go45
-rw-r--r--hugolib/collections.go75
-rw-r--r--hugolib/collections_test.go18
-rw-r--r--hugolib/config.go23
-rw-r--r--hugolib/datafiles_test.go6
-rw-r--r--hugolib/disableKinds_test.go40
-rw-r--r--hugolib/embedded_shortcodes_test.go10
-rw-r--r--hugolib/gitinfo.go14
-rw-r--r--hugolib/hugo_sites.go523
-rw-r--r--hugolib/hugo_sites_build.go175
-rw-r--r--hugolib/hugo_sites_build_errors_test.go123
-rw-r--r--hugolib/hugo_sites_build_test.go509
-rw-r--r--hugolib/hugo_sites_multihost_test.go26
-rw-r--r--hugolib/hugo_smoke_test.go303
-rw-r--r--hugolib/language_content_dir_test.go78
-rw-r--r--hugolib/media.go60
-rw-r--r--hugolib/menu.go224
-rw-r--r--hugolib/menu_test.go6
-rw-r--r--hugolib/minify_publisher_test.go20
-rw-r--r--hugolib/multilingual.go16
-rw-r--r--hugolib/orderedMap.go99
-rw-r--r--hugolib/orderedMap_test.go69
-rw-r--r--hugolib/page.go2360
-rw-r--r--hugolib/pageCache.go136
-rw-r--r--hugolib/pageCache_test.go88
-rw-r--r--hugolib/pageGroup.go298
-rw-r--r--hugolib/pageGroup_test.go457
-rw-r--r--hugolib/pageSort.go332
-rw-r--r--hugolib/pageSort_test.go281
-rw-r--r--hugolib/page__common.go112
-rw-r--r--hugolib/page__content.go135
-rw-r--r--hugolib/page__data.go70
-rw-r--r--hugolib/page__menus.go74
-rw-r--r--hugolib/page__meta.go652
-rw-r--r--hugolib/page__new.go291
-rw-r--r--hugolib/page__output.go107
-rw-r--r--hugolib/page__paginator.go83
-rw-r--r--hugolib/page__paths.go148
-rw-r--r--hugolib/page__per_output.go445
-rw-r--r--hugolib/page__position.go76
-rw-r--r--hugolib/page__ref.go (renamed from hugolib/page_ref.go)61
-rw-r--r--hugolib/page__tree.go113
-rw-r--r--hugolib/page_content.go233
-rw-r--r--hugolib/page_errors.go47
-rw-r--r--hugolib/page_kinds.go40
-rw-r--r--hugolib/page_output.go320
-rw-r--r--hugolib/page_paths.go312
-rw-r--r--hugolib/page_paths_test.go194
-rw-r--r--hugolib/page_permalink_test.go44
-rw-r--r--hugolib/page_taxonomy_test.go96
-rw-r--r--hugolib/page_test.go901
-rw-r--r--hugolib/page_time_integration_test.go183
-rw-r--r--hugolib/page_unwrap.go50
-rw-r--r--hugolib/page_unwrap_test.go (renamed from hugolib/page_resource.go)26
-rw-r--r--hugolib/page_without_content.go67
-rw-r--r--hugolib/pagebundler.go42
-rw-r--r--hugolib/pagebundler_capture.go10
-rw-r--r--hugolib/pagebundler_capture_test.go12
-rw-r--r--hugolib/pagebundler_handlers.go141
-rw-r--r--hugolib/pagebundler_test.go308
-rw-r--r--hugolib/pagecollections.go279
-rw-r--r--hugolib/pagecollections_test.go86
-rw-r--r--hugolib/pagemeta/page_frontmatter.go426
-rw-r--r--hugolib/pagemeta/page_frontmatter_test.go261
-rw-r--r--hugolib/pagemeta/pagemeta.go32
-rw-r--r--hugolib/pagesPrevNext.go42
-rw-r--r--hugolib/pagesPrevNext_test.go86
-rw-r--r--hugolib/pages_language_merge.go64
-rw-r--r--hugolib/pages_language_merge_test.go40
-rw-r--r--hugolib/pages_related.go191
-rw-r--r--hugolib/pages_related_test.go75
-rw-r--r--hugolib/pagination.go595
-rw-r--r--hugolib/pagination_test.go579
-rw-r--r--hugolib/path_separators_test.go38
-rw-r--r--hugolib/paths/themes.go4
-rw-r--r--hugolib/permalinker.go5
-rw-r--r--hugolib/permalinks.go213
-rw-r--r--hugolib/permalinks_test.go85
-rw-r--r--hugolib/resource_chain_test.go8
-rw-r--r--hugolib/rss_test.go25
-rw-r--r--hugolib/shortcode.go490
-rw-r--r--hugolib/shortcode_page.go56
-rw-r--r--hugolib/shortcode_test.go400
-rw-r--r--hugolib/site.go1132
-rw-r--r--hugolib/siteJSONEncode_test.go34
-rw-r--r--hugolib/site_output.go15
-rw-r--r--hugolib/site_output_test.go42
-rw-r--r--hugolib/site_render.go444
-rw-r--r--hugolib/site_sections.go273
-rw-r--r--hugolib/site_sections_test.go150
-rw-r--r--hugolib/site_test.go123
-rw-r--r--hugolib/site_url_test.go14
-rw-r--r--hugolib/sitemap.go45
-rw-r--r--hugolib/sitemap_test.go10
-rw-r--r--hugolib/taxonomy.go151
-rw-r--r--hugolib/taxonomy_test.go161
-rw-r--r--hugolib/testhelpers_test.go123
-rw-r--r--hugolib/translations.go56
100 files changed, 6705 insertions, 11988 deletions
diff --git a/hugolib/alias.go b/hugolib/alias.go
index c44f32dbb..599821c0a 100644
--- a/hugolib/alias.go
+++ b/hugolib/alias.go
@@ -1,4 +1,4 @@
-// Copyright 2017 The Hugo Authors. All rights reserved.
+// Copyright 2019 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.
@@ -26,6 +26,7 @@ import (
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/publisher"
+ "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/tpl"
"github.com/gohugoio/hugo/helpers"
@@ -55,7 +56,12 @@ func newAliasHandler(t tpl.TemplateFinder, l *loggers.Logger, allowRoot bool) al
return aliasHandler{t, l, allowRoot}
}
-func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (io.Reader, error) {
+type aliasPage struct {
+ Permalink string
+ page.Page
+}
+
+func (a aliasHandler) renderAlias(isXHTML bool, permalink string, p page.Page) (io.Reader, error) {
t := "alias"
if isXHTML {
t = "alias-xhtml"
@@ -75,12 +81,9 @@ func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (i
}
}
- data := struct {
- Permalink string
- Page *Page
- }{
+ data := aliasPage{
permalink,
- page,
+ p,
}
buffer := new(bytes.Buffer)
@@ -91,11 +94,11 @@ func (a aliasHandler) renderAlias(isXHTML bool, permalink string, page *Page) (i
return buffer, nil
}
-func (s *Site) writeDestAlias(path, permalink string, outputFormat output.Format, p *Page) (err error) {
+func (s *Site) writeDestAlias(path, permalink string, outputFormat output.Format, p page.Page) (err error) {
return s.publishDestAlias(false, path, permalink, outputFormat, p)
}
-func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, outputFormat output.Format, p *Page) (err error) {
+func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, outputFormat output.Format, p page.Page) (err error) {
handler := newAliasHandler(s.Tmpl, s.Log, allowRoot)
isXHTML := strings.HasSuffix(path, ".xhtml")
@@ -126,19 +129,19 @@ func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, outputFo
func (a aliasHandler) targetPathAlias(src string) (string, error) {
originalAlias := src
if len(src) <= 0 {
- return "", fmt.Errorf("Alias \"\" is an empty string")
+ return "", fmt.Errorf("alias \"\" is an empty string")
}
alias := filepath.Clean(src)
components := strings.Split(alias, helpers.FilePathSeparator)
if !a.allowRoot && alias == helpers.FilePathSeparator {
- return "", fmt.Errorf("Alias \"%s\" resolves to website root directory", originalAlias)
+ return "", fmt.Errorf("alias \"%s\" resolves to website root directory", originalAlias)
}
// Validate against directory traversal
if components[0] == ".." {
- return "", fmt.Errorf("Alias \"%s\" traverses outside the website root directory", originalAlias)
+ return "", fmt.Errorf("alias \"%s\" traverses outside the website root directory", originalAlias)
}
// Handle Windows file and directory naming restrictions
@@ -171,7 +174,7 @@ func (a aliasHandler) targetPathAlias(src string) (string, error) {
for _, m := range msgs {
a.log.ERROR.Println(m)
}
- return "", fmt.Errorf("Cannot create \"%s\": Windows filename restriction", originalAlias)
+ return "", fmt.Errorf("cannot create \"%s\": Windows filename restriction", originalAlias)
}
for _, m := range msgs {
a.log.INFO.Println(m)
diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go
index da1b80b70..684e35c9a 100644
--- a/hugolib/alias_test.go
+++ b/hugolib/alias_test.go
@@ -1,4 +1,4 @@
-// Copyright 2018 The Hugo Authors. All rights reserved.
+// Copyright 2019 The Hugo Authors. All rights reserved.