diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-04-16 17:50:50 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-04-16 18:43:13 +0200 |
commit | 4deb5c60661bdb1d686664f0207f45517a086f29 (patch) | |
tree | 90cf4e7a352ab12970b7851a148accd2bdd5382f /commands | |
parent | 397fce560305d681948ad604ecfd85bd845ad407 (diff) | |
download | hugo-4deb5c60661bdb1d686664f0207f45517a086f29.tar.gz hugo-4deb5c60661bdb1d686664f0207f45517a086f29.zip |
Fix PostProcess regression for hugo server
Fixes #9788
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commandeer.go | 28 | ||||
-rw-r--r-- | commands/commands_test.go | 4 | ||||
-rw-r--r-- | commands/server_test.go | 46 |
3 files changed, 50 insertions, 28 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 1162a4b70..c42de5d11 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -395,23 +395,23 @@ func (c *commandeer) loadConfig() error { } c.fsCreate.Do(func() { - fs := hugofs.NewFrom(sourceFs, config) + // Assume both source and destination are using same filesystem. + fs := hugofs.NewFromSourceAndDestination(sourceFs, sourceFs, config) if c.publishDirFs != nil { // Need to reuse the destination on server rebuilds. fs.PublishDir = c.publishDirFs fs.PublishDirServer = c.publishDirServerFs } else { - publishDir := config.GetString("publishDir") - publishDirStatic := config.GetString("publishDirStatic") - workingDir := config.GetString("workingDir") - absPublishDir := paths.AbsPathify(workingDir, publishDir) - absPublishDirStatic := paths.AbsPathify(workingDir, publishDirStatic) - if c.renderStaticToDisk { - // Writes the dynamic output oton memory, + publishDirStatic := config.GetString("publishDirStatic") + workingDir := config.GetString("workingDir") + absPublishDirStatic := paths.AbsPathify(workingDir, publishDirStatic) + + fs = hugofs.NewFromSourceAndDestination(sourceFs, afero.NewMemMapFs(), config) + // Writes the dynamic output to memory, // while serve others directly from /public on disk. - dynamicFs := afero.NewMemMapFs() + dynamicFs := fs.PublishDir staticFs := afero.NewBasePathFs(afero.NewOsFs(), absPublishDirStatic) // Serve from both the static and dynamic fs, @@ -427,18 +427,10 @@ func (c *commandeer) loadConfig() error { }, }, ) - fs.PublishDir = dynamicFs fs.PublishDirStatic = staticFs } else if createMemFs { // Hugo writes the output to memory instead of the disk. - fs.PublishDir = new(afero.MemMapFs) - fs.PublishDirServer = fs.PublishDir - fs.PublishDirStatic = fs.PublishDir - } else { - // Write everything to disk. - fs.PublishDir = afero.NewBasePathFs(afero.NewOsFs(), absPublishDir) - fs.PublishDirServer = fs.PublishDir - fs.PublishDirStatic = fs.PublishDir + fs = hugofs.NewFromSourceAndDestination(sourceFs, afero.NewMemMapFs(), config) } } diff --git a/commands/commands_test.go b/commands/commands_test.go index e3ec7bd99..97d81ec6e 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -375,6 +375,10 @@ Single: {{ .Title }} List: {{ .Title }} Environment: {{ hugo.Environment }} +For issue 9788: +{{ $foo :="abc" | resources.FromString "foo.css" | minify | resources.PostProcess }} +PostProcess: {{ $foo.RelPermalink }} + `) return dir diff --git a/commands/server_test.go b/commands/server_test.go index ea50afd94..c2aa0dfd5 100644 --- a/commands/server_test.go +++ b/commands/server_test.go @@ -31,16 +31,6 @@ import ( qt "github.com/frankban/quicktest" ) -func TestServer(t *testing.T) { - c := qt.New(t) - - r := runServerTest(c, true, "") - - c.Assert(r.err, qt.IsNil) - c.Assert(r.homeContent, qt.Contains, "List: Hugo Commands") - c.Assert(r.homeContent, qt.Contains, "Environment: development") -} - // Issue 9518 func TestServerPanicOnConfigError(t *testing.T) { c := qt.New(t) @@ -101,6 +91,42 @@ baseURL="https://example.org" } +func TestServerBugs(t *testing.T) { + c := qt.New(t) + + for _, test := range []struct { + name string + flag string + assert func(c *qt.C, r serverTestResult) + }{ + // Issue 9788 + {"PostProcess, memory", "", func(c *qt.C, r serverTestResult) { + c.Assert(r.err, qt.IsNil) + c.Assert(r.homeContent, qt.Contains, "PostProcess: /foo.min.css") + }}, + {"PostProcess, disk", "--renderToDisk", func(c *qt.C, r serverTestResult) { + c.Assert(r.err, qt.IsNil) + c.Assert(r.homeContent, qt.Contains, "PostProcess: /foo.min.css") + }}, + } { + c.Run(test.name, func(c *qt.C) { + config := ` +baseURL="https://example.org" +` + + var args []string + if test.flag != "" { + args = strings.Split(test.flag, "=") + } + r := runServerTest(c, true, config, args...) + test.assert(c, r) + + }) + + } + +} + type serverTestResult struct { err error homeContent string |