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-08-12 17:43:37 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-13 12:44:20 +0300
commitb64617fe4f90da030bcf4a9c5a4913393ce96b14 (patch)
tree07240dbf51bb4afef9ea063f2310c1617be6bb0a /tpl/resources
parent17ca8f0c4c636752fb9da2ad551679275dc03dd3 (diff)
Add resources.Match and resources.GetMatch
Fix #6190
Diffstat (limited to 'tpl/resources')
-rw-r--r--tpl/resources/resources.go46
1 files changed, 42 insertions, 4 deletions
diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go
index d32e12a05..3d688e21c 100644
--- a/tpl/resources/resources.go
+++ b/tpl/resources/resources.go
@@ -68,7 +68,7 @@ type Namespace struct {
templatesClient *templates.Client
}
-// Get locates the filename given in Hugo's filesystems: static, assets and content (in that order)
+// Get locates the filename given in Hugo's assets filesystem
// and creates a Resource object that can be used for further transformations.
func (ns *Namespace) Get(filename interface{}) (resource.Resource, error) {
filenamestr, err := cast.ToStringE(filename)
@@ -78,12 +78,50 @@ func (ns *Namespace) Get(filename interface{}) (resource.Resource, error) {
filenamestr = filepath.Clean(filenamestr)
- // Resource Get'ing is currently limited to /assets to make it simpler
- // to control the behaviour of publishing and partial rebuilding.
- return ns.createClient.Get(ns.deps.BaseFs.Assets.Fs, filenamestr)
+ return ns.createClient.Get(filenamestr)
}
+// GetMatch finds the first Resource matching the given pattern, or nil if none found.
+//
+// It looks for files in the assets file system.
+//
+// See Match for a more complete explanation about the rules used.
+func (ns *Namespace) GetMatch(pattern interface{}) (resource.Resource, error) {
+ patternStr, err := cast.ToStringE(pattern)
+ if err != nil {
+ return nil, err
+ }
+
+ return ns.createClient.GetMatch(patternStr)
+
+}
+
+// Match gets all resources matching the given base path prefix, e.g
+// "*.png" will match all png files. The "*" does not match path delimiters (/),
+// so if you organize your resources in sub-folders, you need to be explicit about it, e.g.:
+// "images/*.png". To match any PNG image anywhere in the bundle you can do "**.png", and
+// to match all PNG images below the images folder, use "images/**.jpg".
+//
+// The matching is case insensitive.
+//
+// Match matches by using the files name with path relative to the file system root
+// with Unix style slashes (/) and no leading slash, e.g. "images/logo.png".
+//
+// See https://github.com/gobwas/glob for the full rules set.
+//
+// It looks for files in the assets file system.
+//
+// See Match for a more complete explanation about the rules used.
+func (ns *Namespace) Match(pattern interface{}) (resource.Resources, error) {
+ patternStr, err := cast.ToStringE(pattern)
+ if err != nil {
+ return nil, err
+ }
+
+ return ns.createClient.Match(patternStr)
+}
+
// Concat concatenates a slice of Resource objects. These resources must
// (currently) be of the same Media Type.
func (ns *Namespace) Concat(targetPathIn interface{}, r interface{}) (resource.Resource, error) {