shithub: hugo

Download patch

ref: ee4a33b14ff2b0a2d9130415e16d1046f72573f7
parent: 09c88e84d196e6c0943b220cd6526d3473c530b6
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Mar 25 15:48:28 EDT 2017

commands: Fix broken commandeer

--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -39,9 +39,22 @@
 	return c.pathSpec
 }
 
+func (c *commandeer) initFs(fs *hugofs.Fs) error {
+	c.DepsCfg.Fs = fs
+	ps, err := helpers.NewPathSpec(fs, c.Cfg)
+	if err != nil {
+		return err
+	}
+	c.pathSpec = ps
+	return nil
+}
+
 func newCommandeer(cfg *deps.DepsCfg) (*commandeer, error) {
-	fs := hugofs.NewDefault(cfg.Language)
-	ps, err := helpers.NewPathSpec(fs, cfg.Cfg)
+	l := cfg.Language
+	if l == nil {
+		l = helpers.NewDefaultLanguage(cfg.Cfg)
+	}
+	ps, err := helpers.NewPathSpec(cfg.Fs, l)
 	if err != nil {
 		return nil, err
 	}
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -18,6 +18,9 @@
 import (
 	"fmt"
 	"io/ioutil"
+
+	"github.com/spf13/hugo/hugofs"
+
 	"log"
 	"net/http"
 	"os"
@@ -28,7 +31,6 @@
 	"time"
 
 	"github.com/spf13/hugo/config"
-	"github.com/spf13/hugo/hugofs"
 
 	"github.com/spf13/hugo/parser"
 	flag "github.com/spf13/pflag"
@@ -288,6 +290,7 @@
 		return cfg, err
 	}
 
+	// Init file systems. This may be changed at a later point.
 	cfg.Cfg = config
 
 	c, err := newCommandeer(cfg)
@@ -343,13 +346,13 @@
 	}
 	config.Set("workingDir", dir)
 
-	cfg.Fs = hugofs.NewFrom(osFs, config)
+	fs := hugofs.NewFrom(osFs, config)
 
 	// Hugo writes the output to memory instead of the disk.
 	// This is only used for benchmark testing. Cause the content is only visible
 	// in memory.
 	if renderToMemory {
-		c.Fs.Destination = new(afero.MemMapFs)
+		fs.Destination = new(afero.MemMapFs)
 		// Rendering to memoryFS, publish to Root regardless of publishDir.
 		c.Set("publishDir", "/")
 	}
@@ -371,7 +374,7 @@
 		if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
 			cacheDir = cacheDir + helpers.FilePathSeparator
 		}
-		isDir, err := helpers.DirExists(cacheDir, cfg.Fs.Source)
+		isDir, err := helpers.DirExists(cacheDir, fs.Source)
 		utils.CheckErr(cfg.Logger, err)
 		if !isDir {
 			mkdir(cacheDir)
@@ -378,8 +381,10 @@
 		}
 		config.Set("cacheDir", cacheDir)
 	} else {
-		config.Set("cacheDir", helpers.GetTempDir("hugo_cache", cfg.Fs.Source))
+		config.Set("cacheDir", helpers.GetTempDir("hugo_cache", fs.Source))
 	}
+
+	c.initFs(fs)
 
 	cfg.Logger.INFO.Println("Using config file:", viper.ConfigFileUsed())