return UnicodeSanitize(strings.ToLower(strings.Replace(strings.TrimSpace(s), " ", "-", -1)))
}
+func MakeTitle(inpath string) string {
+ return strings.Replace(strings.TrimSpace(inpath), "-", " ", -1)
+}
+
func Sanitize(s string) string {
return sanitizeRegexp.ReplaceAllString(s, "")
}
return filepath.Clean(filepath.Join(viper.GetString("WorkingDir"), inPath))
}
+func Filename(in string) (name string) {
+ name, _ = FileAndExt(in)
+ return
+}
+
func FileAndExt(in string) (name string, ext string) {
ext = path.Ext(in)
base := path.Base(in)
return
}
+func GuessSection(in string) string {
+ x := strings.Split(in, "/")
+ x = x[:len(x)-1]
+ if len(x) == 0 {
+ return ""
+ }
+ if x[0] == "content" {
+ x = x[1:]
+ }
+ return path.Join(x...)
+}
+
func PathPrep(ugly bool, in string) string {
if ugly {
return Uglify(in)
return path, nil
}
+func SafeWriteToDisk(inpath string, r io.Reader) (err error) {
+ dir, _ := filepath.Split(inpath)
+ ospath := filepath.FromSlash(dir)
+
+ if ospath != "" {
+ err = os.MkdirAll(ospath, 0777) // rwx, rw, r
+ if err != nil {
+ return
+ }
+ }
+
+ exists, err := Exists(inpath)
+ if err != nil {
+ return
+ }
+ if exists {
+ return fmt.Errorf("%v already exists", inpath)
+ }
+
+ file, err := os.Create(inpath)
+ if err != nil {
+ return
+ }
+ defer file.Close()
+
+ _, err = io.Copy(file, r)
+ return
+}
+
func WriteToDisk(inpath string, r io.Reader) (err error) {
dir, _ := filepath.Split(inpath)
ospath := filepath.FromSlash(dir)