Skip to content

Commit c51db49

Browse files
authored
Im/sitemap (#4332)
* WIP Signed-off-by: Ian Maddaus <[email protected]> * Additional sitemap-main layout updates Signed-off-by: Ian Maddaus <[email protected]> * Update main sitemap layout Signed-off-by: Ian Maddaus <[email protected]> * Update sitemaps param Signed-off-by: Ian Maddaus <[email protected]> --------- Signed-off-by: Ian Maddaus <[email protected]>
1 parent be13245 commit c51db49

File tree

5 files changed

+69
-11
lines changed

5 files changed

+69
-11
lines changed

config/_default/params.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@ menuOrder = [
1717
"legacy",
1818
"extra"
1919
]
20+
2021
enable_search = true
2122
robots = ''
2223

24+
# sitemaps lists sitemaps that are indexed by the main sitemap layout.
25+
# see:
26+
# - layouts/_default/sitemap.xml
27+
# - layouts/_default/home.sitemap-main.xml
28+
29+
sitemaps = [
30+
"https://docs.chef.io/sitemap-main.xml",
31+
"https://docs.chef.io/360/1.0/sitemap.xml"
32+
]
33+
2334
[chef-web-docs]
2435
gh_path = "https://github.com/chef/chef-web-docs/blob/main/content/"
2536

generated/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Config file for generated dir.
22

3-
disableKinds = [ "sitemap", "taxonomy", "term", "RSS", "sitemap"]
3+
disableKinds = [ "sitemap", "taxonomy", "term", "RSS"]
44
publishDir = "generated_content"
55

66
[module]

hugo.toml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,34 @@ pluralizeListTitles = false
77
disableKinds = ["taxonomy", "term"]
88
configDir = "config"
99

10-
# We do redirects using Netlify's _redirects file, generated by Hugo (see "outputs" below).
1110
disableAliases = true
1211
# Summary length
1312
summaryLength = 20
13+
14+
# We do redirects using Netlify's _redirects file, generated by Hugo.
15+
# See the REDIR output and output format and the text/netlify mediatype.
1416
[outputs]
15-
home = [ "HTML", "RSS", "REDIR" ]
16-
section = [ "HTML", "RSS" ]
17+
home = [ "HTML", "RSS", "REDIR", "SITEMAP-MAIN" ]
18+
section = [ "HTML", "RSS" ]
1719

1820
[mediaTypes]
19-
[mediaTypes."text/netlify"]
20-
delimiter = ""
21+
[mediaTypes."text/netlify"]
22+
delimiter = ""
2123

2224
[outputFormats]
23-
[outputFormats.REDIR]
24-
mediatype = "text/netlify"
25-
baseName = "_redirects"
26-
isPlainText = true
27-
notAlternative = true
25+
[outputFormats.REDIR]
26+
mediatype = "text/netlify"
27+
baseName = "_redirects"
28+
isPlainText = true
29+
notAlternative = true
30+
31+
[outputFormats.SITEMAP-MAIN]
32+
MediaType = "application/xml"
33+
BaseName = "sitemap-main"
34+
IsHTML = false
35+
IsPlainText = true
36+
Rel = "sitemap"
37+
protocol = "xml://"
2838

2939
[markup]
3040
[markup.goldmark]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
3+
xmlns:xhtml="http://www.w3.org/1999/xhtml">
4+
{{ range .Site.Pages }}
5+
{{- if or (eq (isset .Params "sitemapexclude") false) (ne .Params.sitemapExclude true) }}
6+
<url>
7+
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
8+
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
9+
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
10+
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
11+
<xhtml:link
12+
rel="alternate"
13+
hreflang="{{ .Language.Lang }}"
14+
href="{{ .Permalink }}"
15+
/>{{ end }}
16+
<xhtml:link
17+
rel="alternate"
18+
hreflang="{{ .Language.Lang }}"
19+
href="{{ .Permalink }}"
20+
/>{{ end }}
21+
</url>
22+
{{- end }}
23+
{{ end }}
24+
</urlset>
25+
26+
<!-- From https://dereckcurry.com/posts/excluding-pages-from-the-sitemap/ -->

layouts/_default/sitemap.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
2+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3+
{{- range .Site.Params.sitemaps }}
4+
<sitemap>
5+
<loc>{{ . }}</loc>
6+
</sitemap>
7+
{{ end -}}
8+
</sitemapindex>
9+
10+
<!-- https://developers.google.com/search/docs/crawling-indexing/sitemaps/large-sitemaps -->
11+
<!-- https://swiftype.com/documentation/site-search/crawler-configuration/sitemap -->

0 commit comments

Comments
 (0)