Skip to content

Commit

Permalink
Prevent 404.html from prettifying into 404/index.html
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anthonyfok authored and bep committed Mar 6, 2015
1 parent 3343cac commit c4c19ad
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,12 @@ func (s *Site) RenderHomePage() error {
}
}

// 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")
Expand All @@ -1269,8 +1275,6 @@ func (s *Site) RenderSitemap() error {

sitemapDefault := parseSitemap(viper.GetStringMap("Sitemap"))

optChanged := false

n := s.NewNode()

// Prepend homepage to the list of pages
Expand All @@ -1296,23 +1300,12 @@ func (s *Site) RenderSitemap() error {
}
}

// 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
}

Expand Down

0 comments on commit c4c19ad

Please sign in to comment.