From 2ac04d1f18aa1f708723cbb9e9eb9e6ba21750d4 Mon Sep 17 00:00:00 2001 From: Ivan Porozhnyy Date: Tue, 31 Jan 2023 12:27:15 +0200 Subject: [PATCH] merge https://github.com/ikeikeikeike/go-sitemap-generator/pull/45 --- stm/builder_url.go | 7 ++++--- stm/sitemap_test.go | 3 +++ stm/utils.go | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/stm/builder_url.go b/stm/builder_url.go index 51af5ee..450e532 100644 --- a/stm/builder_url.go +++ b/stm/builder_url.go @@ -26,13 +26,13 @@ type URLModel struct { News string `valid:"-"` Mobile bool `valid:"-"` Alternate string `valid:"-"` - Alternates map[string]interface{} `valid:"-"` + Alternates map[string]interface{} `valid:"-" structs:"xhtml:link"` Pagemap map[string]interface{} `valid:"-"` } // fieldnames []string{"priority" "changefreq" "lastmod" "expires" "host" "images" -// "video" "geo" "news" "videos" "mobile" "alternate" "alternates" "pagemap"} -var fieldnames = ToLowerString(structs.Names(&URLModel{})) +// "video" "geo" "news" "videos" "mobile" "alternate" "xhtml:link" "pagemap"} +var fieldnames = KeysToLowerString(structs.New(&URLModel{}).Map()) // NewSitemapURL returns the created the SitemapURL's pointer // and it validates URL types error. @@ -115,6 +115,7 @@ func (su *sitemapURL) XML() []byte { SetBuilderElementValue(url, su.data, "video") SetBuilderElementValue(url, su.data, "image") SetBuilderElementValue(url, su.data, "geo") + SetBuilderElementValue(url, su.data, "xhtml:link") if su.opts.pretty { doc.Indent(2) diff --git a/stm/sitemap_test.go b/stm/sitemap_test.go index 5478e03..555e1e1 100644 --- a/stm/sitemap_test.go +++ b/stm/sitemap_test.go @@ -15,6 +15,9 @@ func TestSitemapGenerator(t *testing.T) { sm.SetPretty(true) sm.SetVerbose(false) sm.SetAdapter(&buf) + sm.opts.SetOmitDefaultChangeFreq(false) + sm.opts.SetOmitDefaultPriority(false) + sm.opts.SetOmitDefaultLastMod(false) sm.Create() for i := 1; i <= 10; i++ { diff --git a/stm/utils.go b/stm/utils.go index edac7e4..dc464d9 100644 --- a/stm/utils.go +++ b/stm/utils.go @@ -161,9 +161,9 @@ func MergeMap(src, dst [][]interface{}) [][]interface{} { return src } -// ToLowerString converts lower strings from including capital or upper strings. -func ToLowerString(befores []string) (afters []string) { - for _, name := range befores { +// KeysToLowerString converts lower strings from including capital or upper strings. +func KeysToLowerString(befores map[string]interface{}) (afters []string) { + for name := range befores { afters = append(afters, strings.ToLower(name)) } return afters