Skip to content

Commit 516e6c6

Browse files
committed
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
1 parent 3183b9a commit 516e6c6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

‎hugolib/config.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,5 @@ func loadDefaultSettingsFor(v *viper.Viper) {
131131
v.SetDefault("enableMissingTranslationPlaceholders", false)
132132
v.SetDefault("enableGitInfo", false)
133133
v.SetDefault("ignoreFiles", make([]string, 0))
134+
v.SetDefault("disableAliases", false)
134135
}

‎hugolib/site.go‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -987,14 +987,19 @@ func (s *Site) render(outFormatIdx int) (err error) {
987987
}
988988
s.timerStep("prepare pages")
989989

990-
// Aliases must be rendered before pages.
991-
// Some sites, Hugo docs included, have faulty alias definitions that point
992-
// to itself or another real page. These will be overwritten in the next
993-
// step.
994-
if err = s.renderAliases(); err != nil {
995-
return
990+
// Note that even if disableAliases is set, the aliases themselves are
991+
// preserved on page. The motivation with this is to be able to generate
992+
// 301 redirects in a .htacess file and similar using a custom output format.
993+
if !s.Cfg.GetBool("disableAliases") {
994+
// Aliases must be rendered before pages.
995+
// Some sites, Hugo docs included, have faulty alias definitions that point
996+
// to itself or another real page. These will be overwritten in the next
997+
// step.
998+
if err = s.renderAliases(); err != nil {
999+
return
1000+
}
1001+
s.timerStep("render and write aliases")
9961002
}
997-
s.timerStep("render and write aliases")
9981003

9991004
}
10001005

0 commit comments

Comments
 (0)