summaryrefslogtreecommitdiffstats
path: root/commands/convert.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-05 10:20:06 +0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-17 17:15:26 +0100
commit93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch)
tree5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /commands/convert.go
parente34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff)
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables the use if `t.Parallel` in tests. Updates #2701 Fixes #3016
Diffstat (limited to 'commands/convert.go')
-rw-r--r--commands/convert.go19
1 files changed, 8 insertions, 11 deletions
diff --git a/commands/convert.go b/commands/convert.go
index 79c3c75e8..c24282550 100644
--- a/commands/convert.go
+++ b/commands/convert.go
@@ -21,11 +21,8 @@ import (
"github.com/spf13/cast"
"github.com/spf13/cobra"
- "github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/hugolib"
"github.com/spf13/hugo/parser"
- jww "github.com/spf13/jwalterweatherman"
- "github.com/spf13/viper"
)
var outputDir string
@@ -86,7 +83,7 @@ func convertContents(mark rune) error {
return err
}
- h, err := hugolib.NewHugoSitesFromConfiguration(cfg)
+ h, err := hugolib.NewHugoSites(*cfg)
if err != nil {
return err
}
@@ -104,10 +101,10 @@ func convertContents(mark rune) error {
return errors.New("No source files found")
}
- contentDir := helpers.AbsPathify(viper.GetString("contentDir"))
- jww.FEEDBACK.Println("processing", len(site.Source.Files()), "content files")
+ contentDir := site.PathSpec.AbsPathify(site.Cfg.GetString("contentDir"))
+ site.Log.FEEDBACK.Println("processing", len(site.Source.Files()), "content files")
for _, file := range site.Source.Files() {
- jww.INFO.Println("Attempting to convert", file.LogicalName())
+ site.Log.INFO.Println("Attempting to convert", file.LogicalName())
page, err := site.NewPage(file.LogicalName())
if err != nil {
return err
@@ -115,12 +112,12 @@ func convertContents(mark rune) error {
psr, err := parser.ReadFrom(file.Contents)
if err != nil {
- jww.ERROR.Println("Error processing file:", file.Path())
+ site.Log.ERROR.Println("Error processing file:", file.Path())
return err
}
metadata, err := psr.Metadata()
if err != nil {
- jww.ERROR.Println("Error processing file:", file.Path())
+ site.Log.ERROR.Println("Error processing file:", file.Path())
return err
}
@@ -139,7 +136,7 @@ func convertContents(mark rune) error {
page.SetDir(filepath.Join(contentDir, file.Dir()))
page.SetSourceContent(psr.Content())
if err = page.SetSourceMetaData(metadata, mark); err != nil {
- jww.ERROR.Printf("Failed to set source metadata for file %q: %s. For more info see For more info see https://github.com/spf13/hugo/issues/2458", page.FullFilePath(), err)
+ site.Log.ERROR.Printf("Failed to set source metadata for file %q: %s. For more info see For more info see https://github.com/spf13/hugo/issues/2458", page.FullFilePath(), err)
continue
}
@@ -153,7 +150,7 @@ func convertContents(mark rune) error {
return fmt.Errorf("Failed to save file %q: %s", page.FullFilePath(), err)
}
} else {
- jww.FEEDBACK.Println("Unsafe operation not allowed, use --unsafe or set a different output path")
+ site.Log.FEEDBACK.Println("Unsafe operation not allowed, use --unsafe or set a different output path")
}
}
}