mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
committed by
GitHub
parent
75a823a36a
commit
8aa7257f65
@@ -16,6 +16,7 @@ package resources
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
@@ -107,14 +108,32 @@ func (ns *Namespace) getscssClientDartSass() (*dartsass.Client, error) {
|
||||
return ns.scssClientDartSass, err
|
||||
}
|
||||
|
||||
// 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)
|
||||
// Get locates the filename given in Hugo's assets filesystem or downloads
|
||||
// a file from an URL and creates a Resource object that can be used for
|
||||
// further transformations.
|
||||
//
|
||||
// For URLs an additional argument with options can be provided.
|
||||
func (ns *Namespace) Get(args ...interface{}) (resource.Resource, error) {
|
||||
if len(args) != 1 && len(args) != 2 {
|
||||
return nil, errors.New("must provide a filename or URL")
|
||||
}
|
||||
|
||||
filenamestr, err := cast.ToStringE(args[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if u, err := url.Parse(filenamestr); err == nil && u.Scheme != "" {
|
||||
if len(args) == 2 {
|
||||
options, err := maps.ToStringMapE(args[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ns.createClient.FromRemote(filenamestr, options)
|
||||
}
|
||||
return ns.createClient.FromRemote(filenamestr, nil)
|
||||
}
|
||||
|
||||
filenamestr = filepath.Clean(filenamestr)
|
||||
|
||||
return ns.createClient.Get(filenamestr)
|
||||
|
Reference in New Issue
Block a user