mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Migrating Hugo to Afero for filesystem calls.
This commit is contained in:
@@ -23,9 +23,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/mostafah/fsync"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/fsync"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
"github.com/spf13/hugo/hugolib"
|
||||
"github.com/spf13/hugo/livereload"
|
||||
"github.com/spf13/hugo/utils"
|
||||
@@ -223,6 +224,10 @@ func copyStatic() error {
|
||||
|
||||
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + "/"
|
||||
|
||||
syncer := fsync.NewSyncer()
|
||||
syncer.SrcFs = hugofs.SourceFs
|
||||
syncer.DestFs = hugofs.DestinationFS
|
||||
|
||||
if themeSet() {
|
||||
themeDir := helpers.AbsPathify("themes/"+viper.GetString("theme")) + "/static/"
|
||||
if _, err := os.Stat(themeDir); os.IsNotExist(err) {
|
||||
@@ -232,12 +237,12 @@ func copyStatic() error {
|
||||
|
||||
// Copy Static to Destination
|
||||
jww.INFO.Println("syncing from", themeDir, "to", publishDir)
|
||||
utils.CheckErr(fsync.Sync(publishDir, themeDir), fmt.Sprintf("Error copying static files of theme to %s", publishDir))
|
||||
utils.CheckErr(syncer.Sync(publishDir, themeDir), fmt.Sprintf("Error copying static files of theme to %s", publishDir))
|
||||
}
|
||||
|
||||
// Copy Static to Destination
|
||||
jww.INFO.Println("syncing from", staticDir, "to", publishDir)
|
||||
return fsync.Sync(publishDir, staticDir)
|
||||
return syncer.Sync(publishDir, staticDir)
|
||||
}
|
||||
|
||||
func getDirList() []string {
|
||||
|
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/create"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
"github.com/spf13/hugo/parser"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/viper"
|
||||
@@ -115,9 +116,9 @@ func NewSite(cmd *cobra.Command, args []string) {
|
||||
jww.FATAL.Fatalln(err)
|
||||
}
|
||||
|
||||
if x, _ := helpers.Exists(createpath); x {
|
||||
y, _ := helpers.IsDir(createpath)
|
||||
if z, _ := helpers.IsEmpty(createpath); y && z {
|
||||
if x, _ := helpers.Exists(createpath, hugofs.SourceFs); x {
|
||||
y, _ := helpers.IsDir(createpath, hugofs.SourceFs)
|
||||
if z, _ := helpers.IsEmpty(createpath, hugofs.SourceFs); y && z {
|
||||
jww.INFO.Println(createpath, "already exists and is empty")
|
||||
} else {
|
||||
jww.FATAL.Fatalln(createpath, "already exists and is not empty")
|
||||
@@ -143,7 +144,7 @@ func NewTheme(cmd *cobra.Command, args []string) {
|
||||
createpath := helpers.AbsPathify(path.Join("themes", args[0]))
|
||||
jww.INFO.Println("creating theme at", createpath)
|
||||
|
||||
if x, _ := helpers.Exists(createpath); x {
|
||||
if x, _ := helpers.Exists(createpath, hugofs.SourceFs); x {
|
||||
jww.FATAL.Fatalln(createpath, "already exists")
|
||||
}
|
||||
|
||||
@@ -185,7 +186,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
`)
|
||||
|
||||
err := helpers.WriteToDisk(path.Join(createpath, "LICENSE.md"), bytes.NewReader(by))
|
||||
err := helpers.WriteToDisk(path.Join(createpath, "LICENSE.md"), bytes.NewReader(by), hugofs.SourceFs)
|
||||
if err != nil {
|
||||
jww.FATAL.Fatalln(err)
|
||||
}
|
||||
@@ -205,7 +206,7 @@ func mkdir(x ...string) {
|
||||
func touchFile(x ...string) {
|
||||
inpath := path.Join(x...)
|
||||
mkdir(filepath.Dir(inpath))
|
||||
err := helpers.WriteToDisk(inpath, bytes.NewReader([]byte{}))
|
||||
err := helpers.WriteToDisk(inpath, bytes.NewReader([]byte{}), hugofs.SourceFs)
|
||||
if err != nil {
|
||||
jww.FATAL.Fatalln(err)
|
||||
}
|
||||
@@ -227,7 +228,7 @@ func createThemeMD(inpath string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = helpers.WriteToDisk(path.Join(inpath, "theme.toml"), bytes.NewReader(by))
|
||||
err = helpers.WriteToDisk(path.Join(inpath, "theme.toml"), bytes.NewReader(by), hugofs.SourceFs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -244,7 +245,7 @@ func createConfig(inpath string, kind string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = helpers.WriteToDisk(path.Join(inpath, "config."+kind), bytes.NewReader(by))
|
||||
err = helpers.WriteToDisk(path.Join(inpath, "config."+kind), bytes.NewReader(by), hugofs.SourceFs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@@ -24,8 +24,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
jww "github.com/spf13/jwalterweatherman"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -111,7 +113,8 @@ func serve(port int) {
|
||||
jww.FEEDBACK.Printf("Web Server is available at %s\n", viper.GetString("BaseUrl"))
|
||||
fmt.Println("Press ctrl+c to stop")
|
||||
|
||||
fileserver := http.FileServer(http.Dir(helpers.AbsPathify(viper.GetString("PublishDir"))))
|
||||
httpFs := &afero.HttpFs{SourceFs: hugofs.DestinationFS}
|
||||
fileserver := http.FileServer(httpFs.Dir(helpers.AbsPathify(viper.GetString("PublishDir"))))
|
||||
|
||||
u, err := url.Parse(viper.GetString("BaseUrl"))
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user