mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-15 02:04:02 +00:00
parent
4f66f790b1
commit
cb89ae63e9
2 changed files with 16 additions and 24 deletions
|
@ -1501,6 +1501,21 @@ func readFileFromWorkingDir(i interface{}) (string, error) {
|
||||||
return readFile(hugofs.WorkingDir(), cast.ToString(i))
|
return readFile(hugofs.WorkingDir(), cast.ToString(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// readDirFromWorkingDir listst the directory content relative to the
|
||||||
|
// configured WorkingDir.
|
||||||
|
func readDirFromWorkingDir(i interface{}) ([]os.FileInfo, error) {
|
||||||
|
|
||||||
|
path := cast.ToString(i)
|
||||||
|
|
||||||
|
list, err := afero.ReadDir(hugofs.WorkingDir(), path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Failed to read Directory %s with error message %s", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
// safeHTMLAttr returns a given string as html/template HTMLAttr content.
|
// safeHTMLAttr returns a given string as html/template HTMLAttr content.
|
||||||
//
|
//
|
||||||
// safeHTMLAttr is currently disabled, pending further discussion
|
// safeHTMLAttr is currently disabled, pending further discussion
|
||||||
|
@ -1722,7 +1737,7 @@ func init() {
|
||||||
"partial": partial,
|
"partial": partial,
|
||||||
"plainify": plainify,
|
"plainify": plainify,
|
||||||
"pluralize": pluralize,
|
"pluralize": pluralize,
|
||||||
"readDir": readDir,
|
"readDir": readDirFromWorkingDir,
|
||||||
"readFile": readFileFromWorkingDir,
|
"readFile": readFileFromWorkingDir,
|
||||||
"ref": ref,
|
"ref": ref,
|
||||||
"relURL": func(a string) template.HTML { return template.HTML(helpers.RelURL(a)) },
|
"relURL": func(a string) template.HTML { return template.HTML(helpers.RelURL(a)) },
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -259,25 +258,3 @@ func getCSV(sep string, urlParts ...string) [][]string {
|
||||||
}
|
}
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func readDir(path string) []os.FileInfo {
|
|
||||||
wd := ""
|
|
||||||
p := ""
|
|
||||||
if viper.GetString("WorkingDir") != "" {
|
|
||||||
wd = viper.GetString("WorkingDir")
|
|
||||||
}
|
|
||||||
if strings.Contains(path, "..") {
|
|
||||||
jww.ERROR.Printf("Path %s contains parent directory marker", path)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
p = filepath.Clean(path)
|
|
||||||
p = filepath.Join(wd, p)
|
|
||||||
|
|
||||||
list, err := ioutil.ReadDir(p)
|
|
||||||
if err != nil {
|
|
||||||
jww.ERROR.Printf("Failed to read Directory %s with error message %s", path, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue