diff options
author | cntrump <cntrump@gmail.com> | 2020-05-12 16:51:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-12 16:51:52 +0300 |
commit | 0adfd942521e668702f33f0b7286b01f10cee44c (patch) | |
tree | 52fd5e93cf2119c150c6989fbb89d11d360c27bd | |
parent | a2f758d67a9b6f66e2ee15eff51101cf0f1beed2 (diff) | |
parent | 92e15bc34eee080fe61241cf93382c7da190eda2 (diff) |
Merge pull request #81 from reitzig/add-robots-tag
Set robots meta tag from page front matter.
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | layouts/partials/head.html | 5 | ||||
-rw-r--r-- | layouts/sitemap.xml | 2 |
3 files changed, 17 insertions, 1 deletions
@@ -401,6 +401,17 @@ date = 2020-05-01T22:20:36+08:00 +++ ``` +### Set robots meta tag + +In the front matter of any page, you can selectively enable the `robots` meta tag +and define its content: + +```toml +robots = "noindex,nofollow" +``` + +If `noindex` is included, that page will also be hidden in `sitemap.xml`. + ## Thanks - [**Hugo**](https://gohugo.io/) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index cf34a67..a953574 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -20,4 +20,7 @@ {{- partial "style.html" . -}} {{- partial "rss-feed.html" . -}} {{- partial "twitter-card.html" . -}} -{{- partial "head-extra.html" . -}}
\ No newline at end of file +{{- if .Params.Robots -}} +<meta name="robots" content="{{ .Params.robots }}" /> +{{- end -}} +{{- partial "head-extra.html" . -}} diff --git a/layouts/sitemap.xml b/layouts/sitemap.xml index ae1b5c8..f77c10a 100644 --- a/layouts/sitemap.xml +++ b/layouts/sitemap.xml @@ -2,6 +2,7 @@ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> {{- range .Data.Pages -}} + {{- if not (in .Params.Robots "noindex") -}} <url> <loc>{{- .Permalink -}}</loc>{{- if not .Lastmod.IsZero -}} <lastmod>{{- safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) -}}</lastmod>{{- end -}}{{- with .Sitemap.ChangeFreq -}} @@ -19,4 +20,5 @@ />{{- end -}} </url> {{- end -}} + {{- end -}} </urlset>
\ No newline at end of file |