From 4867cd1dea34ee53fb73cede2bcff4792e470104 Mon Sep 17 00:00:00 2001 From: Jeremy Epstein Date: Sun, 7 Feb 2021 04:30:09 +1100 Subject: [PATCH] tpl/embedded: Exclude pages without Permalink from sitemap --- hugolib/site_test.go | 18 ++++++++++++++---- hugolib/sitemap_test.go | 3 +++ tpl/tplimpl/embedded/templates.autogen.go | 2 ++ .../embedded/templates/_default/sitemap.xml | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 92256342062..8942f38f88e 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -583,11 +583,21 @@ categories = [ "hugo" ] +++ Front Matter with Ordered Pages 4. This is longer content` +var weightedPage5 = `+++ +weight = "5" +title = "Five" + +[_build] +render = "never" ++++ +Front Matter with Ordered Pages 5` + var weightedSources = [][2]string{ {filepath.FromSlash("sect/doc1.md"), weightedPage1}, {filepath.FromSlash("sect/doc2.md"), weightedPage2}, {filepath.FromSlash("sect/doc3.md"), weightedPage3}, {filepath.FromSlash("sect/doc4.md"), weightedPage4}, + {filepath.FromSlash("sect/doc5.md"), weightedPage5}, } func TestOrderedPages(t *testing.T) { @@ -979,8 +989,8 @@ func TestClassCollector(t *testing.T) { b := newTestSitesBuilder(t) b.WithConfigFile("toml", fmt.Sprintf(` - - + + minify = %t [build] @@ -989,7 +999,7 @@ minify = %t `, minify)) b.WithTemplates("index.html", ` - +
Foo
Some text. @@ -1047,7 +1057,7 @@ func TestClassCollectorStress(t *testing.T) { b := newTestSitesBuilder(t) b.WithConfigFile("toml", ` - + disableKinds = ["home", "section", "term", "taxonomy" ] [languages] diff --git a/hugolib/sitemap_test.go b/hugolib/sitemap_test.go index 7302f6e6260..3fa6ab3aeb8 100644 --- a/hugolib/sitemap_test.go +++ b/hugolib/sitemap_test.go @@ -25,12 +25,14 @@ import ( const sitemapTemplate = ` {{ range .Data.Pages }} + {{- if .Permalink -}} {{ .Permalink }}{{ if not .Lastmod.IsZero }} {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} {{ .Sitemap.Priority }}{{ end }} + {{- end -}} {{ end }} ` @@ -80,6 +82,7 @@ func doTestSitemapOutput(t *testing.T, internal bool) { content := readDestination(th, th.Fs, outputSitemap) c.Assert(content, qt.Not(qt.Contains), "404") + c.Assert(content, qt.Not(qt.Contains), "") } func TestParseSitemap(t *testing.T) { diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 27a405bd84a..316d4b1ef70 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -63,6 +63,7 @@ var EmbeddedTemplates = [][2]string{ {{ range .Data.Pages }} + {{- if .Permalink -}} {{ .Permalink }}{{ if not .Lastmod.IsZero }} {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} @@ -79,6 +80,7 @@ var EmbeddedTemplates = [][2]string{ href="{{ .Permalink }}" />{{ end }} + {{- end -}} {{ end }} `}, diff --git a/tpl/tplimpl/embedded/templates/_default/sitemap.xml b/tpl/tplimpl/embedded/templates/_default/sitemap.xml index 63f51195b04..cdb3748e862 100644 --- a/tpl/tplimpl/embedded/templates/_default/sitemap.xml +++ b/tpl/tplimpl/embedded/templates/_default/sitemap.xml @@ -2,6 +2,7 @@ {{ range .Data.Pages }} + {{- if .Permalink -}} {{ .Permalink }}{{ if not .Lastmod.IsZero }} {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} @@ -18,5 +19,6 @@ href="{{ .Permalink }}" />{{ end }} + {{- end -}} {{ end }}