create: Delete redundant viper calls
authorAlbert Nigmatzianov <albertnigma@gmail.com>
Fri, 24 Mar 2017 07:13:05 +0000 (12:13 +0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 24 Mar 2017 21:19:03 +0000 (22:19 +0100)
Also make easier to read the code

create/content.go

index d38d3c7fbc7a4dd1e11d9b59817bb18629a68435..5cab4289b50794c033ec7ccfcb2841f2cb856ea9 100644 (file)
@@ -18,7 +18,6 @@ import (
        "bytes"
        "os"
        "os/exec"
-       "path"
        "path/filepath"
        "strings"
        "time"
@@ -72,17 +71,18 @@ func NewContent(s *hugolib.Site, kind, name string) (err error) {
 
        page.SetSourceContent(psr.Content())
 
-       if err = page.SafeSaveSourceAs(filepath.Join(s.Cfg.GetString("contentDir"), name)); err != nil {
+       contentPath := s.PathSpec.AbsPathify(filepath.Join(s.Cfg.GetString("contentDir"), name))
+
+       if err = page.SafeSaveSourceAs(contentPath); err != nil {
                return
        }
-       jww.FEEDBACK.Println(s.PathSpec.AbsPathify(filepath.Join(s.Cfg.GetString("contentDir"), name)), "created")
+       jww.FEEDBACK.Println(contentPath, "created")
 
        editor := s.Cfg.GetString("newContentEditor")
-
        if editor != "" {
                jww.FEEDBACK.Printf("Editing %s with %q ...\n", name, editor)
 
-               cmd := exec.Command(editor, s.PathSpec.AbsPathify(path.Join(s.Cfg.GetString("contentDir"), name)))
+               cmd := exec.Command(editor, contentPath)
                cmd.Stdin = os.Stdin
                cmd.Stdout = os.Stdout
                cmd.Stderr = os.Stderr