mirror of
https://github.com/gohugoio/hugo.git
synced 2024-07-05 08:42:12 +00:00
hugolib: Add option to disable rendering of 404 page
Fixes #1889 Closes #2037
This commit is contained in:
parent
72bda5ad26
commit
b7efbdc12f
|
@ -127,6 +127,7 @@ var (
|
||||||
canonifyURLs bool
|
canonifyURLs bool
|
||||||
cleanDestination bool
|
cleanDestination bool
|
||||||
enableRobotsTXT bool
|
enableRobotsTXT bool
|
||||||
|
disable404 bool
|
||||||
disableRSS bool
|
disableRSS bool
|
||||||
disableSitemap bool
|
disableSitemap bool
|
||||||
draft bool
|
draft bool
|
||||||
|
@ -214,6 +215,7 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
|
||||||
cmd.Flags().BoolVar(&cleanDestination, "cleanDestinationDir", false, "Remove files from destination not found in static directories")
|
cmd.Flags().BoolVar(&cleanDestination, "cleanDestinationDir", false, "Remove files from destination not found in static directories")
|
||||||
cmd.Flags().BoolVarP(&draft, "buildDrafts", "D", false, "include content marked as draft")
|
cmd.Flags().BoolVarP(&draft, "buildDrafts", "D", false, "include content marked as draft")
|
||||||
cmd.Flags().BoolVarP(&future, "buildFuture", "F", false, "include content with publishdate in the future")
|
cmd.Flags().BoolVarP(&future, "buildFuture", "F", false, "include content with publishdate in the future")
|
||||||
|
cmd.Flags().BoolVar(&disable404, "disable404", false, "Do not render 404 page")
|
||||||
cmd.Flags().BoolVar(&disableRSS, "disableRSS", false, "Do not build RSS files")
|
cmd.Flags().BoolVar(&disableRSS, "disableRSS", false, "Do not build RSS files")
|
||||||
cmd.Flags().BoolVar(&disableSitemap, "disableSitemap", false, "Do not build Sitemap file")
|
cmd.Flags().BoolVar(&disableSitemap, "disableSitemap", false, "Do not build Sitemap file")
|
||||||
cmd.Flags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
|
cmd.Flags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
|
||||||
|
@ -266,6 +268,7 @@ func loadDefaultSettings() {
|
||||||
viper.SetDefault("cleanDestinationDir", false)
|
viper.SetDefault("cleanDestinationDir", false)
|
||||||
viper.SetDefault("Watch", false)
|
viper.SetDefault("Watch", false)
|
||||||
viper.SetDefault("MetaDataFormat", "toml")
|
viper.SetDefault("MetaDataFormat", "toml")
|
||||||
|
viper.SetDefault("Disable404", false)
|
||||||
viper.SetDefault("DisableRSS", false)
|
viper.SetDefault("DisableRSS", false)
|
||||||
viper.SetDefault("DisableSitemap", false)
|
viper.SetDefault("DisableSitemap", false)
|
||||||
viper.SetDefault("DisableRobotsTXT", false)
|
viper.SetDefault("DisableRobotsTXT", false)
|
||||||
|
@ -357,6 +360,9 @@ func InitializeConfig(subCmdVs ...*cobra.Command) error {
|
||||||
if flagChanged(cmdV.Flags(), "canonifyURLs") {
|
if flagChanged(cmdV.Flags(), "canonifyURLs") {
|
||||||
viper.Set("CanonifyURLs", canonifyURLs)
|
viper.Set("CanonifyURLs", canonifyURLs)
|
||||||
}
|
}
|
||||||
|
if flagChanged(cmdV.Flags(), "disable404") {
|
||||||
|
viper.Set("Disable404", disable404)
|
||||||
|
}
|
||||||
if flagChanged(cmdV.Flags(), "disableRSS") {
|
if flagChanged(cmdV.Flags(), "disableRSS") {
|
||||||
viper.Set("DisableRSS", disableRSS)
|
viper.Set("DisableRSS", disableRSS)
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,9 @@ Following is a list of Hugo-defined variables that you can configure and their c
|
||||||
# Do not build Sitemap file
|
# Do not build Sitemap file
|
||||||
disableSitemap: false
|
disableSitemap: false
|
||||||
# Build robots.txt file
|
# Build robots.txt file
|
||||||
enableRobotsTXT: false
|
enableRobotsTXT: false
|
||||||
|
# Do not render 404 page
|
||||||
|
disable404: false
|
||||||
# edit new content with this editor, if provided
|
# edit new content with this editor, if provided
|
||||||
editor: ""
|
editor: ""
|
||||||
# Enable Emoji emoticons support for page content.
|
# Enable Emoji emoticons support for page content.
|
||||||
|
|
|
@ -1769,6 +1769,10 @@ func (s *Site) renderHomePage() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if viper.GetBool("Disable404") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(bep) reusing the Home Node smells trouble
|
// TODO(bep) reusing the Home Node smells trouble
|
||||||
n.URL = helpers.URLize("404.html")
|
n.URL = helpers.URLize("404.html")
|
||||||
n.IsHome = false
|
n.IsHome = false
|
||||||
|
|
Loading…
Reference in a new issue