Skip to content

Commit

Permalink
[Feature Request #81]: Added support for customizable noindex in Hugo…
Browse files Browse the repository at this point in the history
… Pages
  • Loading branch information
1bl4z3r committed Sep 9, 2024
1 parent ada84be commit cca0ce9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion content/posts/explaining-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ Lastmod : 2024-03-12T20:30:30+05:30
- `pin` : Specify if the post should be shown as pinned
- `denyRobots` : Specify what directives to follow when denying crawlers. Default is **noindex, nofollow, noarchive**
- `allowRobots` : Specify what directives to follow when allowing crawlers. Default is **index, follow**
- `noIndex` : When set to true, whole site will have ___noindex, nofollow, noarchive___ (unless specified by `denyRobots`) added to robots meta tag. Else, robots tag will have ___index, follow___ (unless specified by `allowRobots`) applied to whole site
- `siteNoIndex` : When set to true, whole site will have ___noindex, nofollow, noarchive___ (unless specified by `denyRobots`) added to robots meta tag. Else, robots tag will have ___index, follow___ (unless specified by `allowRobots`) applied to whole site
- `noIndexPages` : Specify on which pages crawlers will be denied. Use **Page title** to select pages. Useful for the pages generated by Hugo. (Eg. for [List of Tags]({{<ref "/tags">}}), use ___Tags___)

## Special Caveats

Expand Down
3 changes: 2 additions & 1 deletion hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ expiryDate = ["expiryDate"]
human = ["single","posts"]
# denyRobots = "noindex, nofollow, noarchive"
# allowRobots = "index, follow"
# noIndex = false
# siteNoIndex = false
# noIndexPages = ["404 Page not found"]

[[params.socialLinks]]
name = "github"
Expand Down
3 changes: 2 additions & 1 deletion hugo.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ expiryDate = ["expiryDate"]
# noIndex = false
# denyRobots = "noindex, nofollow, noarchive"
# allowRobots = "index, follow"
# noIndex = false
# siteNoIndex = false
# noIndexPages = ["404 Page not found"]


[[params.socialLinks]]
Expand Down
3 changes: 2 additions & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<link rel="stylesheet preload prefetch" as="style" href="{{ $c_css.Permalink }}" {{ printf "integrity=%q" $c_css.Data.Integrity | safeHTMLAttr }} crossorigin="anonymous">
{{- end -}}
{{- block "head" . -}}{{- end -}}
{{- if templates.Exists "partials/extra-head.html" -}}{{- partial "extra-head.html" . -}}{{- end -}}</head>
{{- if templates.Exists "partials/extra-head.html" -}}{{- partial "extra-head.html" . -}}{{- end -}}
</head>
<body id="page">
{{- if .Site.Params.googleTagManager -}}{{- partial "googleTagManager_body.html" . -}}{{- end -}}
{{- block "header" . -}}{{ end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/site-meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
{{- if (or (in .Page.RelPermalink "404") (or .Site.Params.noIndex .Params.noIndex)) -}}
{{- if (or (in .Page.RelPermalink "404") (or .Site.Params.siteNoIndex .Params.noIndex) (in .Site.Params.noIndexPages .Title)) -}}
<meta name="robots" content="{{ .Site.Params.denyRobots | default "noindex, nofollow, noarchive" }}">
{{- else -}}
<meta name="robots" content="{{ .Site.Params.allowRobots | default "index, follow" }}">
Expand Down

0 comments on commit cca0ce9

Please sign in to comment.