diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-08-13 11:01:57 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-08-13 19:00:51 +0200 |
commit | 78f8475a054a6277d37f13329afd240b00dc9408 (patch) | |
tree | 92c30c046d64f4b4baa4a99a2183deb9c4dee1fe /hugolib | |
parent | c09ee78fd235599d3fb794110cd75c024d80cfca (diff) |
Fix Resource output in multihost setups
In Hugo 0.46 we made the output of what you get from resources.Get and similar static, i.e. language agnostic. This makes total sense, as it is wasteful and time-consuming to do SASS/SCSS/PostCSS processing for lots of languages when the output is lots of duplicates with different filenames.
But since we now output the result once only, this had a negative side effect for multihost setups: We publish the resource once only to the root folder (i.e. not to the language "domain folder").
This commit removes the language code from the processed image keys. This creates less duplication in the file cache, but it means that you should do a `hugo --gc` to clean up stale files.
Fixes #5058
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/hugo_sites_multihost_test.go | 6 | ||||
-rw-r--r-- | hugolib/page_bundler_handlers.go | 2 | ||||
-rw-r--r-- | hugolib/paths/paths.go | 20 | ||||
-rw-r--r-- | hugolib/testhelpers_test.go | 4 |
4 files changed, 24 insertions, 8 deletions
diff --git a/hugolib/hugo_sites_multihost_test.go b/hugolib/hugo_sites_multihost_test.go index 4062868e6..83d6bfc9e 100644 --- a/hugolib/hugo_sites_multihost_test.go +++ b/hugolib/hugo_sites_multihost_test.go @@ -81,8 +81,10 @@ languageName = "Nynorsk" s2h := s2.getPage(KindHome) assert.Equal("https://example.fr/", s2h.Permalink()) - b.AssertFileContent("public/fr/index.html", "French Home Page") - b.AssertFileContent("public/en/index.html", "Default Home Page") + b.AssertFileContent("public/fr/index.html", "French Home Page", "String Resource: /docs/text/pipes.txt") + b.AssertFileContent("public/fr/text/pipes.txt", "Hugo Pipes") + b.AssertFileContent("public/en/index.html", "Default Home Page", "String Resource: /docs/text/pipes.txt") + b.AssertFileContent("public/en/text/pipes.txt", "Hugo Pipes") // Check paginators b.AssertFileContent("public/en/page/1/index.html", `refresh" content="0; url=https://example.com/docs/"`) diff --git a/hugolib/page_bundler_handlers.go b/hugolib/page_bundler_handlers.go index e0eac3ac4..9050052ac 100644 --- a/hugolib/page_bundler_handlers.go +++ b/hugolib/page_bundler_handlers.go @@ -332,7 +332,7 @@ func (c *contentHandlers) createResource() contentHandler { SourceFile: ctx.source, RelTargetFilename: ctx.target, URLBase: c.s.GetURLLanguageBasePath(), - TargetPathBase: c.s.GetTargetLanguageBasePath(), + TargetBasePaths: []string{c.s.GetTargetLanguageBasePath()}, }) return handlerResult{err: err, handled: true, resource: resource} diff --git a/hugolib/paths/paths.go b/hugolib/paths/paths.go index 3be034fef..10acf0cb3 100644 --- a/hugolib/paths/paths.go +++ b/hugolib/paths/paths.go @@ -53,6 +53,10 @@ type Paths struct { PublishDir string + // When in multihost mode, this returns a list of base paths below PublishDir + // for each language. + MultihostTargetBasePaths []string + DisablePathToLower bool RemovePathAccents bool UglyURLs bool @@ -135,6 +139,15 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) { absResourcesDir = FilePathSeparator } + multilingual := cfg.GetBool("multilingual") + + var multihostTargetBasePaths []string + if multilingual { + for _, l := range languages { + multihostTargetBasePaths = append(multihostTargetBasePaths, l.Lang) + } + } + p := &Paths{ Fs: fs, Cfg: cfg, @@ -154,12 +167,13 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) { themes: config.GetStringSlicePreserveString(cfg, "theme"), - multilingual: cfg.GetBool("multilingual"), + multilingual: multilingual, defaultContentLanguageInSubdir: cfg.GetBool("defaultContentLanguageInSubdir"), DefaultContentLanguage: defaultContentLanguage, - Language: language, - Languages: languages, + Language: language, + Languages: languages, + MultihostTargetBasePaths: multihostTargetBasePaths, PaginatePath: cfg.GetString("paginatePath"), } diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 4ba951449..ec84449ec 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -403,8 +403,8 @@ date: "2018-02-28" defaultTemplates = []string{ "_default/single.html", "Single: {{ .Title }}|{{ i18n \"hello\" }}|{{.Lang}}|{{ .Content }}", "_default/list.html", "{{ $p := .Paginator }}List Page {{ $p.PageNumber }}: {{ .Title }}|{{ i18n \"hello\" }}|{{ .Permalink }}|Pager: {{ template \"_internal/pagination.html\" . }}", - "index.html", "{{ $p := .Paginator }}Default Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}", - "index.fr.html", "{{ $p := .Paginator }}French Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}", + "index.html", "{{ $p := .Paginator }}Default Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}", + "index.fr.html", "{{ $p := .Paginator }}French Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}", // Shortcodes "shortcodes/shortcode.html", "Shortcode: {{ i18n \"hello\" }}", |