From 4180a1f894a043e152466aa0ce9e73a2b12edc77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 17 Feb 2019 10:58:03 +0100 Subject: [PATCH] Fix resource outputformat logic --- hugolib/pagebundler_handlers.go | 24 +++++++++++++++++++++++- hugolib/site_render.go | 19 ++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/hugolib/pagebundler_handlers.go b/hugolib/pagebundler_handlers.go index e83d8c6f434..27d69624e8d 100644 --- a/hugolib/pagebundler_handlers.go +++ b/hugolib/pagebundler_handlers.go @@ -16,6 +16,7 @@ package hugolib import ( "errors" "fmt" + "path" "path/filepath" "github.com/gohugoio/hugo/common/hugio" @@ -330,13 +331,34 @@ func (c *contentHandlers) createResource() contentHandler { return notHandled } + // TODO(bep) consolidate with multihost logic + clean up + outputFormats := ctx.parentPage.m.outputFormats() + languageBase := c.s.GetURLLanguageBasePath() + seen := make(map[string]bool) + var targetBasePaths []string + for _, f := range outputFormats { + if !seen[f.Path] { + targetBasePaths = append(targetBasePaths, f.Path) + } + + var lf string + if f.Path == "" { + lf = languageBase + } else { + lf = path.Join(languageBase, f.Path) + } + if !seen[lf] { + targetBasePaths = append(targetBasePaths, lf) + } + } + resource, err := c.s.ResourceSpec.New( resources.ResourceSourceDescriptor{ TargetPathBuilder: ctx.parentPage.subResourceTargetPathFactory, SourceFile: ctx.source, RelTargetFilename: ctx.target, URLBase: c.s.GetURLLanguageBasePath(), - TargetBasePaths: []string{c.s.GetTargetLanguageBasePath()}, + TargetBasePaths: targetBasePaths, }) return handlerResult{err: err, handled: true, result: resource} diff --git a/hugolib/site_render.go b/hugolib/site_render.go index 5eb9a98a9cb..f1b7ed96fdb 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -113,23 +113,8 @@ func pageRenderer(s *Site, pages <-chan *pageState, results chan<- error, wg *sy continue } - // We only need to re-publish the resources if the output format is different - // from all of the previous (e.g. the "amp" use case). - // TODO(bep) page - shouldRender := true - - /* shouldRender := i == 0 - if i > 0 { - for j := i; j >= 0; j-- { - if f.Path != p.m.configuredOutputFormats[j].Path { - shouldRender = true - } else { - shouldRender = false - } - } - }*/ - - if shouldRender { + if i == 0 { + // This will publish its resources to all output formats paths. if err := p.renderResources(); err != nil { s.SendError(p.errorf(err, "failed to render page resources")) continue