From bf0dfa3e2d2688aea4a97c8c0fadd1207263ca96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 30 Sep 2016 16:24:09 +0200 Subject: [PATCH] Fix URL in multilanguage sitemap index Fixes #2509 --- hugolib/hugo_sites_test.go | 8 ++++---- hugolib/site.go | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hugolib/hugo_sites_test.go b/hugolib/hugo_sites_test.go index baaa0ce8f..b7a52b1e4 100644 --- a/hugolib/hugo_sites_test.go +++ b/hugolib/hugo_sites_test.go @@ -116,8 +116,8 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) { // Sitemaps behaves different: In a multilanguage setup there will always be a index file and // one sitemap in each lang folder. assertFileContent(t, "public/sitemap.xml", true, - "http:/example.com/blog/en/sitemap.xml", - "http:/example.com/blog/fr/sitemap.xml") + "http://example.com/blog/en/sitemap.xml", + "http://example.com/blog/fr/sitemap.xml") if defaultInSubDir { assertFileContent(t, "public/fr/sitemap.xml", true, "http://example.com/blog/fr/") @@ -313,8 +313,8 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { // 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) + 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) diff --git a/hugolib/site.go b/hugolib/site.go index 8066dbefc..5f02a2c7a 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -878,7 +878,12 @@ func (s *SiteInfo) HomeAbsURL() string { // 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) + p := s.HomeAbsURL() + if !strings.HasSuffix(p, "/") { + p += "/" + } + p += sitemapDefault.Filename + return p } func (s *Site) initializeSiteInfo() {