Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-05-03 10:16:58 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-07-24 10:35:53 +0300
commit9f5a92078a3f388b52d597b5a59af5c933a112d2 (patch)
tree0b2b07e5b3a3f21877bc5585a4bdd76306a09dde /resources/page
parent47953148b6121441d0147c960a99829c53b5a5ba (diff)
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
Diffstat (limited to 'resources/page')
-rw-r--r--resources/page/page_nop.go5
-rw-r--r--resources/page/page_wrappers.autogen.go4
-rw-r--r--resources/page/pagemeta/page_frontmatter.go2
-rw-r--r--resources/page/permalinks.go5
-rw-r--r--resources/page/site.go71
-rw-r--r--resources/page/testhelpers_test.go11
-rw-r--r--resources/page/zero_file.autogen.go4
7 files changed, 93 insertions, 9 deletions
diff --git a/resources/page/page_nop.go b/resources/page/page_nop.go
index 229bcb077..c3a4819f1 100644
--- a/resources/page/page_nop.go
+++ b/resources/page/page_nop.go
@@ -17,9 +17,10 @@ package page
import (
"html/template"
- "os"
"time"
+ "github.com/gohugoio/hugo/hugofs"
+
"github.com/bep/gitmap"
"github.com/gohugoio/hugo/navigation"
@@ -147,7 +148,7 @@ func (p *nopPage) File() source.File {
return nilFile
}
-func (p *nopPage) FileInfo() os.FileInfo {
+func (p *nopPage) FileInfo() hugofs.FileMetaInfo {
return nil
}
diff --git a/resources/page/page_wrappers.autogen.go b/resources/page/page_wrappers.autogen.go
index d7fcb5201..d2d14dee6 100644
--- a/resources/page/page_wrappers.autogen.go
+++ b/resources/page/page_wrappers.autogen.go
@@ -18,8 +18,8 @@ package page
import (
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/helpers"
+ "github.com/gohugoio/hugo/hugofs"
"html/template"
- "os"
)
// NewDeprecatedWarningPage adds deprecation warnings to the given implementation.
@@ -91,7 +91,7 @@ func (p *pageDeprecated) UniqueID() string {
helpers.Deprecated("Page", ".UniqueID", "Use .File.UniqueID", false)
return p.p.UniqueID()
}
-func (p *pageDeprecated) FileInfo() os.FileInfo {
+func (p *pageDeprecated) FileInfo() hugofs.FileMetaInfo {
helpers.Deprecated("Page", ".FileInfo", "Use .File.FileInfo", false)
return p.p.FileInfo()
}
diff --git a/resources/page/pagemeta/page_frontmatter.go b/resources/page/pagemeta/page_frontmatter.go
index 1ce3fbee4..7b9f13e62 100644
--- a/resources/page/pagemeta/page_frontmatter.go
+++ b/resources/page/pagemeta/page_frontmatter.go
@@ -236,7 +236,7 @@ func addDateFieldAliases(values []string) []string {
complete = append(complete, aliases...)
}
}
- return helpers.UniqueStrings(complete)
+ return helpers.UniqueStringsReuse(complete)
}
func expandDefaultValues(values []string, defaults []string) []string {
diff --git a/resources/page/permalinks.go b/resources/page/permalinks.go
index 98489231b..59f2da916 100644
--- a/resources/page/permalinks.go
+++ b/resources/page/permalinks.go
@@ -15,6 +15,7 @@ package page
import (
"fmt"
+ "os"
"path/filepath"
"regexp"
"strconv"
@@ -90,7 +91,11 @@ func (l PermalinkExpander) parse(patterns map[string]string) (map[string]func(Pa
expanders := make(map[string]func(Page) (string, error))
+ // Allow " " and / to represent the root section.
+ const sectionCutSet = " /" + string(os.PathSeparator)
+
for k, pattern := range patterns {
+ k = strings.Trim(k, sectionCutSet)
if !l.validate(pattern) {
return nil, &permalinkExpandError{pattern: pattern, err: errPermalinkIllFormed}
}
diff --git a/resources/page/site.go b/resources/page/site.go
index 25df063f1..9153c8556 100644
--- a/resources/page/site.go
+++ b/resources/page/site.go
@@ -17,6 +17,8 @@ import (
"html/template"
"time"
+ "github.com/gohugoio/hugo/config"
+
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/navigation"
@@ -51,3 +53,72 @@ func (s Sites) First() Site {
}
return s[0]
}
+
+type testSite struct {
+ h hugo.Info
+ l *langs.Language
+}
+
+func (t testSite) Hugo() hugo.Info {
+ return t.h
+}
+
+func (t testSite) ServerPort() int {
+ return 1313
+}
+
+func (testSite) LastChange() (t time.Time) {
+ return
+}
+
+func (t testSite) Title() string {
+ return "foo"
+}
+
+func (t testSite) Sites() Sites {
+ return nil
+}
+
+func (t testSite) IsServer() bool {
+ return false
+}
+
+func (t testSite) Language() *langs.Language {
+ return t.l
+}
+
+func (t testSite) Pages() Pages {
+ return nil
+}
+
+func (t testSite) RegularPages() Pages {
+ return nil
+}
+
+func (t testSite) Menus() navigation.Menus {
+ return nil
+}
+
+func (t testSite) Taxonomies() interface{} {
+ return nil
+}
+
+func (t testSite) BaseURL() template.URL {
+ return ""
+}
+
+func (t testSite) Params() map[string]interface{} {
+ return nil
+}
+
+func (t testSite) Data() map[string]interface{} {
+ return nil
+}
+
+// NewDummyHugoSite creates a new minimal test site.
+func NewDummyHugoSite(cfg config.Provider) Site {
+ return testSite{
+ h: hugo.NewInfo(hugo.EnvironmentProduction),
+ l: langs.NewLanguage("en", cfg),
+ }
+}
diff --git a/resources/page/testhelpers_test.go b/resources/page/testhelpers_test.go
index 60a6c0816..fa5f8e9c8 100644
--- a/resources/page/testhelpers_test.go
+++ b/resources/page/testhelpers_test.go
@@ -16,10 +16,11 @@ package page
import (
"fmt"
"html/template"
- "os"
"path/filepath"
"time"
+ "github.com/gohugoio/hugo/modules"
+
"github.com/bep/gitmap"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resources/resource"
@@ -65,6 +66,12 @@ func newTestPathSpec() *helpers.PathSpec {
func newTestPathSpecFor(cfg config.Provider) *helpers.PathSpec {
config.SetBaseTestDefaults(cfg)
+ langs.LoadLanguageSettings(cfg, nil)
+ mod, err := modules.CreateProjectModule(cfg)
+ if err != nil {
+ panic(err)
+ }
+ cfg.Set("allModules", modules.Modules{mod})
fs := hugofs.NewMem(cfg)
s, err := helpers.NewPathSpec(fs, cfg)
if err != nil {
@@ -189,7 +196,7 @@ func (p *testPage) File() source.File {
return p.file
}
-func (p *testPage) FileInfo() os.FileInfo {
+func (p *testPage) FileInfo() hugofs.FileMetaInfo {
panic("not implemented")
}
diff --git a/resources/page/zero_file.autogen.go b/resources/page/zero_file.autogen.go
index eec1dd66d..23e36b764 100644
--- a/resources/page/zero_file.autogen.go
+++ b/resources/page/zero_file.autogen.go
@@ -17,8 +17,8 @@ package page
import (
"github.com/gohugoio/hugo/helpers"
+ "github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/source"
- "os"
)
// ZeroFile represents a zero value of source.File with warnings if invoked.
@@ -82,7 +82,7 @@ func (z zeroFile) UniqueID() (o0 string) {
z.log.Println(".File.UniqueID on zero object. Wrap it in if or with: {{ with .File }}{{ .UniqueID }}{{ end }}")
return
}
-func (z zeroFile) FileInfo() (o0 os.FileInfo) {
+func (z zeroFile) FileInfo() (o0 hugofs.FileMetaInfo) {
z.log.Println(".File.FileInfo on zero object. Wrap it in if or with: {{ with .File }}{{ .FileInfo }}{{ end }}")
return
}