github.com/jamiefdhurst/journal@v0.9.2/internal/app/controller/web/sitemap.go (about)

     1  package web
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  	"text/template"
     7  
     8  	"github.com/jamiefdhurst/journal/internal/app"
     9  	"github.com/jamiefdhurst/journal/internal/app/model"
    10  	"github.com/jamiefdhurst/journal/pkg/controller"
    11  )
    12  
    13  // Sitemap Generate an XML sitemap
    14  type Sitemap struct {
    15  	controller.Super
    16  	Journals []model.Journal
    17  }
    18  
    19  // Run Sitemap
    20  func (c *Sitemap) Run(response http.ResponseWriter, request *http.Request) {
    21  
    22  	container := c.Super.Container.(*app.Container)
    23  	js := model.Journals{Container: container, Gs: model.GiphyAdapter(container)}
    24  
    25  	c.Journals = js.FetchAll()
    26  
    27  	log.Println(c.Host)
    28  
    29  	response.Header().Add("Content-type", "text/xml")
    30  	template, _ := template.ParseFiles("./web/templates/sitemap.xml.tmpl")
    31  	template.ExecuteTemplate(response, "content", c)
    32  }