mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-26 00:32:07 +00:00
79d9f82e79
It started with wanting to move templates in template bundles and the rest followed. I did my best to start grouping related functions together, but there are some that I missed. There is also the method Urlize that seems to be a special function used in both worlds. I'll need to revisit this method.
34 lines
572 B
Go
34 lines
572 B
Go
package hugolib
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func fileExt(path string) (file, ext string) {
|
|
if strings.Contains(path, ".") {
|
|
i := len(path) - 1
|
|
for path[i] != '.' {
|
|
i--
|
|
}
|
|
return path[:i], path[i+1:]
|
|
}
|
|
return path, ""
|
|
}
|
|
|
|
func replaceExtension(path string, newExt string) string {
|
|
f, _ := fileExt(path)
|
|
return f + "." + newExt
|
|
}
|
|
|
|
// Check if Exists && is Directory
|
|
func dirExists(path string) (bool, error) {
|
|
fi, err := os.Stat(path)
|
|
if err == nil && fi.IsDir() {
|
|
return true, nil
|
|
}
|
|
if os.IsNotExist(err) {
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|