shithub: hugo

Download patch

ref: bf0dfa3e2d2688aea4a97c8c0fadd1207263ca96
parent: d30c6a26d1e7e85cec1711e192b0f9df04b6a4c2
author: Bjørn Erik Pedersen <[email protected]>
date: Fri Sep 30 12:24:09 EDT 2016

Fix URL in multilanguage sitemap index

Fixes #2509

--- a/hugolib/hugo_sites_test.go
+++ b/hugolib/hugo_sites_test.go
@@ -116,8 +116,8 @@
 	// 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 @@
 
 	// 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)
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -878,7 +878,12 @@
 // 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() {