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
}
}
- 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)
}(pageChan, wg)
}
- for _, p := range s.AllPages {
+ for _, p := range s.Pages {
pageChan <- p
}
wg.Wait()
- return nil
}
// Pages returns all pages for all sites.
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)
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)
}
// 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)
}
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"),
---
# doc1
*some "content"*
+
+{{< shortcode >}}
+
NOTE: slug should be used as URL
`)},
{filepath.FromSlash("sect/doc1.fr.md"), []byte(`---
---
# doc1
*quelque "contenu"*
+
+{{< shortcode >}}
+
NOTE: should be in the 'en' Page's 'Translations' field.
NOTE: date is after "doc3"
`)},
}
}
-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
}