Fix URL in multilanguage sitemap index
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 30 Sep 2016 14:24:09 +0000 (16:24 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 30 Sep 2016 14:24:57 +0000 (16:24 +0200)
Fixes #2509

hugolib/hugo_sites_test.go
hugolib/site.go

index baaa0ce8fd8f35524ace32e8f209f9e6487e0e42..b7a52b1e4f1126b2a96bc21a98374cbee5ec5e65 100644 (file)
@@ -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,
-               "<loc>http:/example.com/blog/en/sitemap.xml</loc>",
-               "<loc>http:/example.com/blog/fr/sitemap.xml</loc>")
+               "<loc>http://example.com/blog/en/sitemap.xml</loc>",
+               "<loc>http://example.com/blog/fr/sitemap.xml</loc>")
 
        if defaultInSubDir {
                assertFileContent(t, "public/fr/sitemap.xml", true, "<loc>http://example.com/blog/fr/</loc>")
@@ -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, "<loc>http:/example.com/blog/en/sitemap.xml</loc>"), sitemapIndex)
-       require.True(t, strings.Contains(sitemapIndex, "<loc>http:/example.com/blog/fr/sitemap.xml</loc>"), sitemapIndex)
+       require.True(t, strings.Contains(sitemapIndex, "<loc>http://example.com/blog/en/sitemap.xml</loc>"), sitemapIndex)
+       require.True(t, strings.Contains(sitemapIndex, "<loc>http://example.com/blog/fr/sitemap.xml</loc>"), 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)
index 8066dbefc4c740313ec5eb4e0112b4974e3e3486..5f02a2c7af3ccd21ecdeb88618d6ff28bd596782 100644 (file)
@@ -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() {