diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-20 10:30:40 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-20 11:03:34 +0200 |
commit | 516e6c6dc5733cdaf985317d58eedbc6ec0ef2f7 (patch) | |
tree | 8d1c15fc782585daf4e60bca4f0928d15fb5e042 | |
parent | 3183b9a29d8adac962fbc73f79b04542f4c4c55d (diff) |
hugolib: Add disableAliases
Note that even with this setting enabled, the aliases themselves are preserved on the pages.
The big motivation for this change is to be able to use the alias definitions to generate `.htaccess` or Netlify's `_redirect` files with server-side redirects.
Fixes #3613
-rw-r--r-- | hugolib/config.go | 1 | ||||
-rw-r--r-- | hugolib/site.go | 19 |
2 files changed, 13 insertions, 7 deletions
diff --git a/hugolib/config.go b/hugolib/config.go index 62cdea952..7779a4d83 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -131,4 +131,5 @@ func loadDefaultSettingsFor(v *viper.Viper) { v.SetDefault("enableMissingTranslationPlaceholders", false) v.SetDefault("enableGitInfo", false) v.SetDefault("ignoreFiles", make([]string, 0)) + v.SetDefault("disableAliases", false) } diff --git a/hugolib/site.go b/hugolib/site.go index 829023d15..8aa1e087f 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -987,14 +987,19 @@ func (s *Site) render(outFormatIdx int) (err error) { } s.timerStep("prepare pages") - // Aliases must be rendered before pages. - // Some sites, Hugo docs included, have faulty alias definitions that point - // to itself or another real page. These will be overwritten in the next - // step. - if err = s.renderAliases(); err != nil { - return + // Note that even if disableAliases is set, the aliases themselves are + // preserved on page. The motivation with this is to be able to generate + // 301 redirects in a .htacess file and similar using a custom output format. + if !s.Cfg.GetBool("disableAliases") { + // Aliases must be rendered before pages. + // Some sites, Hugo docs included, have faulty alias definitions that point + // to itself or another real page. These will be overwritten in the next + // step. + if err = s.renderAliases(); err != nil { + return + } + s.timerStep("render and write aliases") } - s.timerStep("render and write aliases") } |