summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-06-02 23:41:46 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-06-02 23:41:46 +0200
commit1283f3d31243d1ac63ce718c4039ba6b85f5d721 (patch)
treea2d0cf8358d9a2da5aff67fd8129279a2b6a2bfd
parentc39ce7b2605f525d42072ea1aa9d930f34857ab6 (diff)
downloadgohugo-theme-ed-1283f3d31243d1ac63ce718c4039ba6b85f5d721.tar.gz
Provide ability to hide particular page from the sitemap
-rw-r--r--CHANGELOG.md2
-rw-r--r--layouts/_default/sitemap.xml24
2 files changed, 26 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2c9da82..cf92297 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Provide ability to include custom scripts in the theme
- Provide ability to specify custom language of a post
- Add tagging support
+- Provide ability to hide particular page from the sitemap by using
+ `private: true` in front matter
### Changed
diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml
new file mode 100644
index 0000000..3745dc5
--- /dev/null
+++ b/layouts/_default/sitemap.xml
@@ -0,0 +1,24 @@
+{{- $dateFormat := site.Params.dateFormatFeed | default "2006-01-02T15:04:05-07:00" -}}
+
+{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml">
+ {{ range .Data.Pages }}{{ if ne .Params.private true }}
+ <url>
+ <loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
+ <lastmod>{{ safeHTML ( .Lastmod.Format $dateFormat | html ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
+ <changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
+ <priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
+ <xhtml:link
+ rel="alternate"
+ hreflang="{{ .Language.Lang }}"
+ href="{{ .Permalink }}"
+ />{{ end }}
+ <xhtml:link
+ rel="alternate"
+ hreflang="{{ .Language.Lang }}"
+ href="{{ .Permalink }}"
+ />{{ end }}
+ </url>
+ {{ end }}{{ end }}
+</urlset>