shithub: hugo

Download patch

ref: c4c19ad303cb11616a7291bdbeec997e59b6d24e
parent: 3343cacc0e5a94ca50537cb5612b5549be2d9ca0
author: Anthony Fok <[email protected]>
date: Thu Mar 5 23:47:04 EST 2015

Prevent 404.html from prettifying into 404/index.html

Restore @realchaseadams's commit 348e123
"Force `UglyUrls` option to force `404.html` file name"
which got lost after some refactoring (commit 8db3c0b).

Remove the equivalent "force `UglyUrls`" code for `sitemap.xml`
because the refactored code now calls `renderAndWriteXML()`
which uses `WriteDestFile()` which does not prettify a filename.

Fixes #939

--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1250,6 +1250,12 @@
 		}
 	}
 
+	// Force `UglyUrls` option to force `404.html` file name
+	if !s.PageTarget().(*target.PagePub).UglyUrls {
+		s.PageTarget().(*target.PagePub).UglyUrls = true
+		defer func() { s.PageTarget().(*target.PagePub).UglyUrls = false }()
+	}
+
 	n.Url = helpers.Urlize("404.html")
 	n.Title = "404 Page not found"
 	n.Permalink = s.permalink("404.html")
@@ -1269,8 +1275,6 @@
 
 	sitemapDefault := parseSitemap(viper.GetStringMap("Sitemap"))
 
-	optChanged := false
-
 	n := s.NewNode()
 
 	// Prepend homepage to the list of pages
@@ -1296,21 +1300,10 @@
 		}
 	}
 
-	// Force `UglyUrls` option to force `sitemap.xml` file name
-	switch s.PageTarget().(type) {
-	case *target.Filesystem:
-		s.PageTarget().(*target.PagePub).UglyUrls = true
-		optChanged = true
-	}
-
 	smLayouts := []string{"sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml"}
 
 	if err := s.renderAndWriteXML("sitemap", "sitemap.xml", n, s.appendThemeTemplates(smLayouts)...); err != nil {
 		return err
-	}
-
-	if optChanged {
-		s.PageTarget().(*target.PagePub).UglyUrls = viper.GetBool("UglyUrls")
 	}
 
 	return nil