Merge to stay up to date with current dev

Feature: GetJson and GetJson in short codes or other layout files.
For more details please see: http://cyrillschumacher.com/2014/12/21/dynamic-pages-with-gohugo.io/
This commit is contained in:
Cyrill Schumacher
2014-12-27 14:40:10 +11:00
committed by spf13
parent 9bf223e584
commit 5e2d3d2e10
5 changed files with 465 additions and 1 deletions

View File

@@ -437,3 +437,28 @@ func WriteToDisk(inpath string, r io.Reader, fs afero.Fs) (err error) {
_, err = io.Copy(file, r)
return
}
// GetTempDir returns the OS default temp directory with trailing slash
// if subPath is not empty then it will be created recursively
func GetTempDir(subPath string, fs afero.Fs) string {
dir := os.TempDir()
if FilePathSeparator != dir[len(dir)-1:] {
dir = dir + FilePathSeparator
}
if subPath != "" {
dir = dir + MakePath(subPath)
if exists, _ := Exists(dir, fs); exists {
return dir
}
err := fs.MkdirAll(dir, 0777) // rwx, rw, r
if err != nil {
panic(err)
}
if FilePathSeparator != dir[len(dir)-1:] {
dir = dir + FilePathSeparator
}
}
return dir
}