Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cntrump/hugo-notepadium.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcntrump <cntrump@gmail.com>2020-05-12 16:51:52 +0300
committerGitHub <noreply@github.com>2020-05-12 16:51:52 +0300
commit0adfd942521e668702f33f0b7286b01f10cee44c (patch)
tree52fd5e93cf2119c150c6989fbb89d11d360c27bd
parenta2f758d67a9b6f66e2ee15eff51101cf0f1beed2 (diff)
parent92e15bc34eee080fe61241cf93382c7da190eda2 (diff)
Merge pull request #81 from reitzig/add-robots-tag
Set robots meta tag from page front matter.
-rw-r--r--README.md11
-rw-r--r--layouts/partials/head.html5
-rw-r--r--layouts/sitemap.xml2
3 files changed, 17 insertions, 1 deletions
diff --git a/README.md b/README.md
index e4b98cf..e6167ae 100644
--- a/README.md
+++ b/README.md
@@ -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