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 is currently disabled, pending further discussion
"partial": partial,
"plainify": plainify,
"pluralize": pluralize,
- "readDir": readDir,
+ "readDir": readDirFromWorkingDir,
"readFile": readFileFromWorkingDir,
"ref": ref,
"relURL": func(a string) template.HTML { return template.HTML(helpers.RelURL(a)) },
"io/ioutil"
"net/http"
"net/url"
- "os"
"path/filepath"
"strings"
"sync"
}
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
-}