mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
7cc637e97a
commit
d3d3863c05
4 changed files with 33 additions and 13 deletions
|
@ -569,6 +569,7 @@ func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
||||||
p := s.newNodePage(NodeTaxonomyTerms)
|
p := s.newNodePage(NodeTaxonomyTerms)
|
||||||
p.sections = []string{plural}
|
p.sections = []string{plural}
|
||||||
p.Title = strings.Title(plural)
|
p.Title = strings.Title(plural)
|
||||||
|
s.setPageURLs(p, plural)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ func (*PageCollections) findPagesByNodeTypeNotIn(n NodeType, inPages Pages) Page
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PageCollections) findAllPagesByNodeType(n NodeType) Pages {
|
func (c *PageCollections) findAllPagesByNodeType(n NodeType) Pages {
|
||||||
return c.findPagesByNodeTypeIn(n, c.rawAllPages)
|
return c.findPagesByNodeTypeIn(n, c.Nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PageCollections) findRawAllPagesByNodeType(n NodeType) Pages {
|
func (c *PageCollections) findRawAllPagesByNodeType(n NodeType) Pages {
|
||||||
|
|
|
@ -182,19 +182,18 @@ func (s *Site) renderSitemap() error {
|
||||||
|
|
||||||
n := s.newNodePage(NodeSitemap)
|
n := s.newNodePage(NodeSitemap)
|
||||||
|
|
||||||
// Prepend homepage to the list of pages
|
// Include all pages (regular, home page, taxonomies etc.)
|
||||||
pages := make(Pages, 0)
|
pages := s.Nodes
|
||||||
|
|
||||||
page := s.newNodePage(NodeSitemap)
|
page := s.newNodePage(NodeSitemap)
|
||||||
page.URLPath.URL = ""
|
page.URLPath.URL = ""
|
||||||
page.Sitemap.ChangeFreq = sitemapDefault.ChangeFreq
|
page.Sitemap.ChangeFreq = sitemapDefault.ChangeFreq
|
||||||
page.Sitemap.Priority = sitemapDefault.Priority
|
page.Sitemap.Priority = sitemapDefault.Priority
|
||||||
|
page.Sitemap.Filename = sitemapDefault.Filename
|
||||||
pages = append(pages, page)
|
|
||||||
pages = append(pages, s.Pages...)
|
|
||||||
|
|
||||||
n.Data["Pages"] = pages
|
n.Data["Pages"] = pages
|
||||||
|
|
||||||
|
// TODO(bep) this should be done somewhere else
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
if page.Sitemap.ChangeFreq == "" {
|
if page.Sitemap.ChangeFreq == "" {
|
||||||
page.Sitemap.ChangeFreq = sitemapDefault.ChangeFreq
|
page.Sitemap.ChangeFreq = sitemapDefault.ChangeFreq
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/spf13/hugo/helpers"
|
"github.com/spf13/hugo/helpers"
|
||||||
"github.com/spf13/hugo/source"
|
"github.com/spf13/hugo/source"
|
||||||
|
@ -36,6 +35,12 @@ const SITEMAP_TEMPLATE = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap
|
||||||
</urlset>`
|
</urlset>`
|
||||||
|
|
||||||
func TestSitemapOutput(t *testing.T) {
|
func TestSitemapOutput(t *testing.T) {
|
||||||
|
for _, internal := range []bool{false, true} {
|
||||||
|
doTestSitemapOutput(t, internal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doTestSitemapOutput(t *testing.T, internal bool) {
|
||||||
testCommonResetState()
|
testCommonResetState()
|
||||||
|
|
||||||
viper.Set("baseURL", "http://auth/bub/")
|
viper.Set("baseURL", "http://auth/bub/")
|
||||||
|
@ -45,15 +50,30 @@ func TestSitemapOutput(t *testing.T) {
|
||||||
Language: helpers.NewDefaultLanguage(),
|
Language: helpers.NewDefaultLanguage(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := buildAndRenderSite(s, "sitemap.xml", SITEMAP_TEMPLATE); err != nil {
|
if internal {
|
||||||
t.Fatalf("Failed to build site: %s", err)
|
if err := buildAndRenderSite(s); err != nil {
|
||||||
|
t.Fatalf("Failed to build site: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if err := buildAndRenderSite(s, "sitemap.xml", SITEMAP_TEMPLATE); err != nil {
|
||||||
|
t.Fatalf("Failed to build site: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sitemapContent := readDestination(t, "public/sitemap.xml")
|
assertFileContent(t, "public/sitemap.xml", true,
|
||||||
|
// Regular page
|
||||||
|
" <loc>http://auth/bub/sect/doc1/</loc>",
|
||||||
|
// Home page
|
||||||
|
"<loc>http://auth/bub/</loc>",
|
||||||
|
// Section
|
||||||
|
"<loc>http://auth/bub/sect/</loc>",
|
||||||
|
// Tax terms
|
||||||
|
"<loc>http://auth/bub/categories/</loc>",
|
||||||
|
// Tax list
|
||||||
|
"<loc>http://auth/bub/categories/hugo/</loc>",
|
||||||
|
)
|
||||||
|
|
||||||
if !strings.HasPrefix(sitemapContent, "<?xml") {
|
|
||||||
t.Errorf("Sitemap file should start with <?xml. %s", sitemapContent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseSitemap(t *testing.T) {
|
func TestParseSitemap(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue