Do not create robots.txt by default
Meny people, including me, have a custom robots.txt in static. Also remove that option from the command line; it doesn't feel important enough. Fixes ##2049
This commit is contained in:
parent
43b5dfabb5
commit
54750b0780
5 changed files with 8 additions and 9 deletions
|
@ -126,7 +126,7 @@ var (
|
||||||
buildWatch bool
|
buildWatch bool
|
||||||
canonifyURLs bool
|
canonifyURLs bool
|
||||||
cleanDestination bool
|
cleanDestination bool
|
||||||
disableRobotsTXT bool
|
enableRobotsTXT bool
|
||||||
disableRSS bool
|
disableRSS bool
|
||||||
disableSitemap bool
|
disableSitemap bool
|
||||||
draft bool
|
draft bool
|
||||||
|
@ -216,7 +216,6 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
|
||||||
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(&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().BoolVar(&disableRobotsTXT, "disableRobotsTXT", false, "Do not build Robots TXT 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")
|
||||||
cmd.Flags().StringVarP(&contentDir, "contentDir", "c", "", "filesystem path to content directory")
|
cmd.Flags().StringVarP(&contentDir, "contentDir", "c", "", "filesystem path to content directory")
|
||||||
cmd.Flags().StringVarP(&layoutDir, "layoutDir", "l", "", "filesystem path to layout directory")
|
cmd.Flags().StringVarP(&layoutDir, "layoutDir", "l", "", "filesystem path to layout directory")
|
||||||
|
@ -364,8 +363,8 @@ func InitializeConfig(subCmdVs ...*cobra.Command) error {
|
||||||
if flagChanged(cmdV.Flags(), "disableSitemap") {
|
if flagChanged(cmdV.Flags(), "disableSitemap") {
|
||||||
viper.Set("DisableSitemap", disableSitemap)
|
viper.Set("DisableSitemap", disableSitemap)
|
||||||
}
|
}
|
||||||
if flagChanged(cmdV.Flags(), "disableRobotsTXT") {
|
if flagChanged(cmdV.Flags(), "enableRobotsTXT") {
|
||||||
viper.Set("DisableRobotsTXT", disableRobotsTXT)
|
viper.Set("EnableRobotsTXT", enableRobotsTXT)
|
||||||
}
|
}
|
||||||
if flagChanged(cmdV.Flags(), "pluralizeListTitles") {
|
if flagChanged(cmdV.Flags(), "pluralizeListTitles") {
|
||||||
viper.Set("PluralizeListTitles", pluralizeListTitles)
|
viper.Set("PluralizeListTitles", pluralizeListTitles)
|
||||||
|
|
|
@ -13,13 +13,12 @@ weight: 120
|
||||||
Hugo can generated a customized [robots.txt](http://www.robotstxt.org/) in the
|
Hugo can generated a customized [robots.txt](http://www.robotstxt.org/) in the
|
||||||
[same way as any other templates]({{< ref "templates/go-templates.md" >}}).
|
[same way as any other templates]({{< ref "templates/go-templates.md" >}}).
|
||||||
|
|
||||||
By default, it generates a robots.txt, which allows everything, with the following content:
|
To enable it, just set `enableRobotsTXT` option to `true` in the [configuration file]({{< ref "overview/configuration.md" >}}). By default, it generates a robots.txt, which allows everything, with the following content:
|
||||||
|
|
||||||
```http
|
```http
|
||||||
User-agent: *
|
User-agent: *
|
||||||
```
|
```
|
||||||
|
|
||||||
To disable it, just set `disableRobotsTXT` option to `false` in the [command line]({{< ref "commands/hugo.md" >}}) or [configuration file]({{< ref "overview/configuration.md" >}}).
|
|
||||||
|
|
||||||
Hugo will use the template `robots.txt` according to the following list in descending precedence:
|
Hugo will use the template `robots.txt` according to the following list in descending precedence:
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,8 @@ Following is a list of Hugo-defined variables that you can configure and their c
|
||||||
disableRSS: false
|
disableRSS: false
|
||||||
# Do not build Sitemap file
|
# Do not build Sitemap file
|
||||||
disableSitemap: false
|
disableSitemap: false
|
||||||
# Do not build robots.txt file
|
# Build robots.txt file
|
||||||
disableRobotsTXT: false
|
enableRobotsTXT: 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.
|
||||||
|
|
|
@ -36,6 +36,7 @@ func TestRobotsTXTOutput(t *testing.T) {
|
||||||
hugofs.InitMemFs()
|
hugofs.InitMemFs()
|
||||||
|
|
||||||
viper.Set("baseurl", "http://auth/bub/")
|
viper.Set("baseurl", "http://auth/bub/")
|
||||||
|
viper.Set("enableRobotsTXT", true)
|
||||||
|
|
||||||
s := &Site{
|
s := &Site{
|
||||||
Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
|
Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
|
||||||
|
|
|
@ -1864,7 +1864,7 @@ func (s *Site) RenderSitemap() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) RenderRobotsTXT() error {
|
func (s *Site) RenderRobotsTXT() error {
|
||||||
if viper.GetBool("DisableRobotsTXT") {
|
if !viper.GetBool("EnableRobotsTXT") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue