Rework the Destination filesystem to make --renderStaticToDisk work

See #9626
This commit is contained in:
Bjørn Erik Pedersen
2022-03-21 09:35:15 +01:00
parent b08193971a
commit d070bdf10f
75 changed files with 651 additions and 566 deletions

View File

@@ -18,6 +18,8 @@ import (
"path/filepath"
"strings"
hpaths "github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/modules"
@@ -51,6 +53,7 @@ type Paths struct {
// pagination path handling
PaginatePath string
// TODO1 check usage
PublishDir string
// When in multihost mode, this returns a list of base paths below PublishDir
@@ -123,7 +126,7 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
languages = langs.Languages{&langs.Language{Lang: "en", Cfg: cfg, ContentDir: contentDir}}
}
absPublishDir := AbsPathify(workingDir, publishDir)
absPublishDir := hpaths.AbsPathify(workingDir, publishDir)
if !strings.HasSuffix(absPublishDir, FilePathSeparator) {
absPublishDir += FilePathSeparator
}
@@ -131,7 +134,7 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
if absPublishDir == "//" {
absPublishDir = FilePathSeparator
}
absResourcesDir := AbsPathify(workingDir, resourceDir)
absResourcesDir := hpaths.AbsPathify(workingDir, resourceDir)
if !strings.HasSuffix(absResourcesDir, FilePathSeparator) {
absResourcesDir += FilePathSeparator
}
@@ -254,7 +257,7 @@ func (p *Paths) GetLangSubDir(lang string) string {
// AbsPathify creates an absolute path if given a relative path. If already
// absolute, the path is just cleaned.
func (p *Paths) AbsPathify(inPath string) string {
return AbsPathify(p.WorkingDir, inPath)
return hpaths.AbsPathify(p.WorkingDir, inPath)
}
// RelPathify trims any WorkingDir prefix from the given filename. If
@@ -267,12 +270,3 @@ func (p *Paths) RelPathify(filename string) string {
return strings.TrimPrefix(strings.TrimPrefix(filename, p.WorkingDir), FilePathSeparator)
}
// AbsPathify creates an absolute path if given a working dir and a relative path.
// If already absolute, the path is just cleaned.
func AbsPathify(workingDir, inPath string) string {
if filepath.IsAbs(inPath) {
return filepath.Clean(inPath)
}
return filepath.Join(workingDir, inPath)
}