Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-08-12 19:17:00 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-06 18:32:21 +0300
commita823b1572ba93444fe60eeba7c2c7b500ac2cd67 (patch)
tree44e1699a6e001faf1c79733b800fb0a0a02a042a /hugolib
parent28696b5dca6b14cfb0935901163d07ce216f9903 (diff)
Set lang template globals for each site when render shortcodes
We should get rid of these globals, but that is another month.
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/hugo_sites.go21
-rw-r--r--hugolib/hugo_sites_test.go22
-rw-r--r--hugolib/site.go8
3 files changed, 40 insertions, 11 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 9aafb953a..8fe27e506 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -394,6 +394,9 @@ func (h *HugoSites) setupTranslations(master *Site) {
func (h *HugoSites) preRender() error {
for _, s := range h.Sites {
+ if err := s.setCurrentLanguageConfig(); err != nil {
+ return err
+ }
// Run "render prepare"
if err := s.renderHomePage(true); err != nil {
return err
@@ -409,12 +412,19 @@ func (h *HugoSites) preRender() error {
}
}
- pageChan := make(chan *Page)
+ for _, s := range h.Sites {
+ if err := s.setCurrentLanguageConfig(); err != nil {
+ return err
+ }
+ renderShortcodesForSite(s)
+ }
- wg := &sync.WaitGroup{}
+ return nil
+}
- // We want all the pages, so just pick one.
- s := h.Sites[0]
+func renderShortcodesForSite(s *Site) {
+ pageChan := make(chan *Page)
+ wg := &sync.WaitGroup{}
for i := 0; i < getGoMaxProcs()*4; i++ {
wg.Add(1)
@@ -456,7 +466,7 @@ func (h *HugoSites) preRender() error {
}(pageChan, wg)
}
- for _, p := range s.AllPages {
+ for _, p := range s.Pages {
pageChan <- p
}
@@ -464,7 +474,6 @@ func (h *HugoSites) preRender() error {
wg.Wait()
- return nil
}
// Pages returns all pages for all sites.
diff --git a/hugolib/hugo_sites_test.go b/hugolib/hugo_sites_test.go
index 152994020..bfbcd914e 100644
--- a/hugolib/hugo_sites_test.go
+++ b/hugolib/hugo_sites_test.go
@@ -258,6 +258,10 @@ func doTestMultiSitesBuild(t *testing.T, configContent, configSuffix string) {
assertFileContent(t, "public/en/index.html", true, "Home Page 1", "Hello", "Hugo Rocks!")
assertFileContent(t, "public/fr/index.html", true, "Home Page 1", "Bonjour", "Hugo Rocks!")
+ // check single page content
+ assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
+ assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello")
+
// Check node translations
homeEn := enSite.getNode("home-0")
require.NotNil(t, homeEn)
@@ -566,8 +570,6 @@ title = "Svenska"
require.Len(t, svPage.Translations(), 2)
require.Len(t, svPage.AllTranslations(), 3)
require.Equal(t, "en", svPage.Translations()[0].Lang())
- //noFile := readDestination(t, "/public/no/doc1/index.html")
- //require.True(t, strings.Contains("foo", noFile), noFile)
}
@@ -719,7 +721,7 @@ func createMultiTestSitesForConfig(t *testing.T, configContent, configSuffix str
// Add some layouts
if err := afero.WriteFile(hugofs.Source(),
filepath.Join("layouts", "_default/single.html"),
- []byte("Single: {{ .Title }}|{{ i18n \"hello\" }} {{ .Content }}"),
+ []byte("Single: {{ .Title }}|{{ i18n \"hello\" }}|{{.Lang}}|{{ .Content }}"),
0755); err != nil {
t.Fatalf("Failed to write layout file: %s", err)
}
@@ -738,6 +740,14 @@ func createMultiTestSitesForConfig(t *testing.T, configContent, configSuffix str
t.Fatalf("Failed to write layout file: %s", err)
}
+ // Add a shortcode
+ if err := afero.WriteFile(hugofs.Source(),
+ filepath.Join("layouts", "shortcodes", "shortcode.html"),
+ []byte("Shortcode: {{ i18n \"hello\" }}"),
+ 0755); err != nil {
+ t.Fatalf("Failed to write layout file: %s", err)
+ }
+
// Add some language files
if err := afero.WriteFile(hugofs.Source(),
filepath.Join("i18n", "en.yaml"),
@@ -769,6 +779,9 @@ publishdate: "2000-01-01"
---
# doc1
*some "content"*
+
+{{< shortcode >}}
+
NOTE: slug should be used as URL
`)},
{filepath.FromSlash("sect/doc1.fr.md"), []byte(`---
@@ -780,6 +793,9 @@ publishdate: "2000-01-04"
---
# doc1
*quelque "contenu"*
+
+{{< shortcode >}}
+
NOTE: should be in the 'en' Page's 'Translations' field.
NOTE: date is after "doc3"
`)},
diff --git a/hugolib/site.go b/hugolib/site.go
index dd020f75c..9f435218c 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -776,11 +776,15 @@ func (s *Site) setupPrevNext() {
}
}
-func (s *Site) render() (err error) {
+func (s *Site) setCurrentLanguageConfig() error {
// There are sadly some global template funcs etc. that need the language information.
viper.Set("Multilingual", s.multilingualEnabled())
viper.Set("CurrentContentLanguage", s.Language)
- if err = tpl.SetTranslateLang(s.Language.Lang); err != nil {
+ return tpl.SetTranslateLang(s.Language.Lang)
+}
+
+func (s *Site) render() (err error) {
+ if err = s.setCurrentLanguageConfig(); err != nil {
return
}