diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 76f9979fd..835603048 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -61,6 +61,14 @@ func (h HugoSites) Reset() {
}
}
+func (h HugoSites) siteInfos() []*SiteInfo {
+ infos := make([]*SiteInfo, len(h.Sites))
+ for i, s := range h.Sites {
+ infos[i] = &s.Info
+ }
+ return infos
+}
+
type BuildCfg struct {
// Whether we are in watch (server) mode
Watching bool
@@ -118,9 +126,9 @@ func (h HugoSites) Build(config BuildCfg) error {
return err
}
- for _, s := range h.Sites {
+ if !config.skipRender {
+ for _, s := range h.Sites {
- if !config.skipRender {
if err := s.Render(); err != nil {
return err
}
@@ -129,7 +137,10 @@ func (h HugoSites) Build(config BuildCfg) error {
s.Stats()
}
}
- // TODO(bep) ml lang in site.Info?
+
+ if err := h.render(); err != nil {
+ return err
+ }
}
if config.PrintStats {
@@ -180,6 +191,10 @@ func (h HugoSites) Rebuild(config BuildCfg, events ...fsnotify.Event) error {
s.Stats()
}
}
+
+ if err := h.render(); err != nil {
+ return err
+ }
}
if config.PrintStats {
@@ -190,6 +205,28 @@ func (h HugoSites) Rebuild(config BuildCfg, events ...fsnotify.Event) error {
}
+// Render the cross-site artifacts.
+func (h *HugoSites) render() error {
+
+ if !h.Multilingual.enabled() {
+ return nil
+ }
+
+ // TODO(bep) DRY
+ sitemapDefault := parseSitemap(viper.GetStringMap("Sitemap"))
+
+ s := h.Sites[0]
+
+ smLayouts := []string{"sitemapindex.xml", "_default/sitemapindex.xml", "_internal/_default/sitemapindex.xml"}
+
+ if err := s.renderAndWriteXML("sitemapindex", sitemapDefault.Filename,
+ h.siteInfos(), s.appendThemeTemplates(smLayouts)...); err != nil {
+ return err
+ }
+
+ return nil
+}
+
func (s *HugoSites) setupTranslations(master *Site) {
for _, p := range master.rawAllPages {
diff --git a/hugolib/hugo_sites_test.go b/hugolib/hugo_sites_test.go
index cbd6bd627..185c241a5 100644
--- a/hugolib/hugo_sites_test.go
+++ b/hugolib/hugo_sites_test.go
@@ -126,11 +126,18 @@ func TestMultiSites(t *testing.T) {
assert.Equal(t, "fr", frenchPage.Lang())
}
+ // Check redirect to main language, French
languageRedirect := readDestination(t, "public/index.html")
-
- // French is the main content language
require.True(t, strings.Contains(languageRedirect, "0; url=http://example.com/blog/fr"), languageRedirect)
+ // Check sitemap(s)
+ sitemapIndex := readDestination(t, "public/sitemap.xml")
+ require.True(t, strings.Contains(sitemapIndex, "http:/example.com/blog/en/sitemap.xml"), sitemapIndex)
+ require.True(t, strings.Contains(sitemapIndex, "http:/example.com/blog/fr/sitemap.xml"), sitemapIndex)
+ sitemapEn := readDestination(t, "public/en/sitemap.xml")
+ sitemapFr := readDestination(t, "public/fr/sitemap.xml")
+ require.True(t, strings.Contains(sitemapEn, "http://example.com/blog/en/sect/doc2/"), sitemapEn)
+ require.True(t, strings.Contains(sitemapFr, "http://example.com/blog/fr/sect/doc1/"), sitemapFr)
}
func TestMultiSitesRebuild(t *testing.T) {
diff --git a/hugolib/public/404.html b/hugolib/public/404.html
deleted file mode 100644
index e69de29bb..000000000
diff --git a/hugolib/public/index.html b/hugolib/public/index.html
deleted file mode 100644
index e69de29bb..000000000
diff --git a/hugolib/public/rss b/hugolib/public/rss
deleted file mode 100644
index bbf739012..000000000
--- a/hugolib/public/rss
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
- /rss/
- Recent content on
- Hugo -- gohugo.io
-
-
-
-
\ No newline at end of file
diff --git a/hugolib/public/sitemap.xml b/hugolib/public/sitemap.xml
deleted file mode 100644
index f02c32c4c..000000000
--- a/hugolib/public/sitemap.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
- /
-
-
-
\ No newline at end of file
diff --git a/hugolib/site.go b/hugolib/site.go
index 776876980..06d7ed074 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -170,10 +170,10 @@ type SiteInfo struct {
paginationPageCount uint64
Data *map[string]interface{}
- Multilingual bool
- CurrentLanguage string
- LanguagePrefix string
- Languages Languages
+ Multilingual bool
+ Language *Language
+ LanguagePrefix string
+ Languages Languages
}
// SiteSocial is a place to put social details on a site level. These are the
@@ -831,6 +831,21 @@ func (s *Site) initialize() (err error) {
return
}
+// HomeURL is a convenience method giving the absolute URL to the home page.
+func (s *SiteInfo) HomeAbsURL() string {
+ base := "/"
+ if s.Multilingual {
+ base = s.Language.Lang
+ }
+ return helpers.AbsURL(base)
+}
+
+// SitemapAbsURL is a convenience method giving the absolute URL to the sitemap.
+func (s *SiteInfo) SitemapAbsURL() string {
+ sitemapDefault := parseSitemap(viper.GetStringMap("Sitemap"))
+ return path.Join(s.HomeAbsURL(), sitemapDefault.Filename)
+}
+
func (s *Site) initializeSiteInfo() {
var (
@@ -864,7 +879,7 @@ func (s *Site) initializeSiteInfo() {
DisqusShortname: lang.GetString("DisqusShortname"),
// TODO(bep) multilang, consolidate the below (make into methods etc.)
Multilingual: s.multilingualEnabled(),
- CurrentLanguage: lang.Lang,
+ Language: lang,
LanguagePrefix: languagePrefix,
Languages: languages,
GoogleAnalytics: lang.GetString("GoogleAnalytics"),
diff --git a/tpl/template_embedded.go b/tpl/template_embedded.go
index dae36a297..c13768dda 100644
--- a/tpl/template_embedded.go
+++ b/tpl/template_embedded.go
@@ -100,6 +100,19 @@ func (t *GoHTMLTemplate) EmbedTemplates() {
{{ end }}
`)
+ // For multilanguage sites
+ t.AddInternalTemplate("_default", "sitemapindex.xml", `
+ {{ range . }}
+
+ {{ .SitemapAbsURL }}
+ {{ if not .LastChange.IsZero }}
+ {{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}
+ {{ end }}
+
+ {{ end }}
+
+`)
+
t.AddInternalTemplate("", "pagination.html", `{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}