diff --git a/go.mod b/go.mod index 304307c..df32ec5 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/spf13/cast v1.4.0 github.com/spf13/viper v1.8.1 github.com/stretchr/testify v1.7.0 - github.com/tdewolff/minify/v2 v2.9.20 + github.com/tdewolff/minify/v2 v2.9.21 github.com/thoas/go-funk v0.9.0 github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 github.com/vcraescu/go-paginator v1.0.1-0.20201114172518-2cfc59fe05c2 diff --git a/go.sum b/go.sum index aaa2c24..4e8f3c0 100644 --- a/go.sum +++ b/go.sum @@ -346,8 +346,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/tdewolff/minify/v2 v2.9.20 h1:Fut7w3T7nWfDOb/bOgyEvshQRRMt+xzi1T7spEEKXDw= -github.com/tdewolff/minify/v2 v2.9.20/go.mod h1:PoDBts2L7sCwUT28vTAlozGeD6qxjrrihtin4bR/RMM= +github.com/tdewolff/minify/v2 v2.9.21 h1:nO4s1PEMy7aRjlIlbr3Jgr+bJby8QYuifa2Vs2f9lh4= +github.com/tdewolff/minify/v2 v2.9.21/go.mod h1:PoDBts2L7sCwUT28vTAlozGeD6qxjrrihtin4bR/RMM= github.com/tdewolff/parse/v2 v2.5.19 h1:Kjaj3KQOx/4elIxlBSglus4E2oMfdROphvbq2b+OBZ0= github.com/tdewolff/parse/v2 v2.5.19/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho= github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4= diff --git a/sitemap.go b/sitemap.go index a6b2d3c..f77cd32 100644 --- a/sitemap.go +++ b/sitemap.go @@ -3,6 +3,7 @@ package main import ( "bytes" "database/sql" + "encoding/xml" "net/http" "github.com/araddon/dateparse" @@ -28,7 +29,7 @@ func (a *goBlog) serveSitemap(w http.ResponseWriter, r *http.Request) { }) } // Write sitemap - a.writeSitemapIndex(w, sm) + a.writeSitemapXML(w, sm) } func (a *goBlog) serveSitemapBlog(w http.ResponseWriter, r *http.Request) { @@ -46,7 +47,7 @@ func (a *goBlog) serveSitemapBlog(w http.ResponseWriter, r *http.Request) { Loc: a.getFullAddress(a.getRelativePath(b, sitemapBlogPostsPath)), }) // Write sitemap - a.writeSitemapIndex(w, sm) + a.writeSitemapXML(w, sm) } func (a *goBlog) serveSitemapBlogFeatures(w http.ResponseWriter, r *http.Request) { @@ -101,7 +102,7 @@ func (a *goBlog) serveSitemapBlogFeatures(w http.ResponseWriter, r *http.Request }) } // Write sitemap - a.writeSitemap(w, sm) + a.writeSitemapXML(w, sm) } func (a *goBlog) serveSitemapBlogArchives(w http.ResponseWriter, r *http.Request) { @@ -144,7 +145,7 @@ func (a *goBlog) serveSitemapBlogArchives(w http.ResponseWriter, r *http.Request }) } // Write sitemap - a.writeSitemap(w, sm) + a.writeSitemapXML(w, sm) } // Serve sitemap with all the blog's posts @@ -167,23 +168,17 @@ func (a *goBlog) serveSitemapBlogPosts(w http.ResponseWriter, r *http.Request) { sm.Add(item) } // Write sitemap - a.writeSitemap(w, sm) + a.writeSitemapXML(w, sm) } -func (a *goBlog) writeSitemap(w http.ResponseWriter, sm *sitemap.Sitemap) { - var buf bytes.Buffer - sm.WriteTo(&buf) - a.writeSitemapXML(w, &buf) -} - -func (a *goBlog) writeSitemapIndex(w http.ResponseWriter, sm *sitemap.SitemapIndex) { - var buf bytes.Buffer - sm.WriteTo(&buf) - a.writeSitemapXML(w, &buf) -} - -func (a *goBlog) writeSitemapXML(w http.ResponseWriter, buf *bytes.Buffer) { +func (a *goBlog) writeSitemapXML(w http.ResponseWriter, sm interface{}) { w.Header().Set(contentType, contenttype.XMLUTF8) + var buf bytes.Buffer + buf.WriteString(xml.Header) + buf.WriteString(``) + xml.NewEncoder(&buf).Encode(sm) a.min.Write(w, contenttype.XML, buf.Bytes()) } diff --git a/templateAssets.go b/templateAssets.go index 0e9a5f3..11b70be 100644 --- a/templateAssets.go +++ b/templateAssets.go @@ -51,12 +51,17 @@ func (a *goBlog) compileAsset(name string) (string, error) { m := a.min.Get() switch ext { case ".js": - content, err = m.Bytes("application/javascript", content) + content, err = m.Bytes(contenttype.JS, content) if err != nil { return "", err } case ".css": - content, err = m.Bytes("text/css", content) + content, err = m.Bytes(contenttype.CSS, content) + if err != nil { + return "", err + } + case ".xml", ".xsl": + content, err = m.Bytes(contenttype.XML, content) if err != nil { return "", err } diff --git a/templates/assets/sitemap.xsl b/templates/assets/sitemap.xsl new file mode 100644 index 0000000..0736855 --- /dev/null +++ b/templates/assets/sitemap.xsl @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + + + +
+ + +
+
\ No newline at end of file