shithub: hugo

Download patch

ref: 58f8b43feed9a487e63b61352226d934743ebafe
parent: f271faea066c47817c8a9a62ef5509a151452d6a
author: spf13 <[email protected]>
date: Thu May 1 09:13:11 EDT 2014

moving writeToDisk to helpers to make it more accessible

--- a/helpers/path.go
+++ b/helpers/path.go
@@ -15,6 +15,7 @@
 
 import (
 	"fmt"
+	"io"
 	"os"
 	"path"
 	"path/filepath"
@@ -21,6 +22,7 @@
 	"regexp"
 	"strings"
 	"unicode"
+
 	"github.com/spf13/viper"
 )
 
@@ -150,4 +152,25 @@
 	}
 
 	return path, nil
+}
+
+func WriteToDisk(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 {
+			panic(err)
+		}
+	}
+
+	file, err := os.Create(inpath)
+	if err != nil {
+		return
+	}
+	defer file.Close()
+
+	_, err = io.Copy(file, r)
+	return
 }
--- a/target/file.go
+++ b/target/file.go
@@ -3,9 +3,9 @@
 import (
 	"fmt"
 	"io"
-	"os"
 	"path"
-	"path/filepath"
+
+	"github.com/spf13/hugo/helpers"
 )
 
 type Publisher interface {
@@ -34,28 +34,7 @@
 		return
 	}
 
-	return writeToDisk(translated, r)
-}
-
-func writeToDisk(translated string, r io.Reader) (err error) {
-	path, _ := filepath.Split(translated)
-	ospath := filepath.FromSlash(path)
-
-	if ospath != "" {
-		err = os.MkdirAll(ospath, 0777) // rwx, rw, r
-		if err != nil {
-			panic(err)
-		}
-	}
-
-	file, err := os.Create(translated)
-	if err != nil {
-		return
-	}
-	defer file.Close()
-
-	_, err = io.Copy(file, r)
-	return
+	return helpers.WriteToDisk(translated, r)
 }
 
 func (fs *Filesystem) Translate(src string) (dest string, err error) {
--- a/target/htmlredirect.go
+++ b/target/htmlredirect.go
@@ -2,10 +2,11 @@
 
 import (
 	"bytes"
-	"github.com/spf13/hugo/helpers"
 	"html/template"
 	"path"
 	"strings"
+
+	"github.com/spf13/hugo/helpers"
 )
 
 const ALIAS = "<!DOCTYPE html><html><head><link rel=\"canonical\" href=\"{{ .Permalink }}\"/><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /><meta http-equiv=\"refresh\" content=\"0;url={{ .Permalink }}\" /></head></html>"
@@ -67,5 +68,5 @@
 		return
 	}
 
-	return writeToDisk(path, buffer)
+	return helpers.WriteToDisk(path, buffer)
 }