Example #1
0
func produceFeedXML(w http.ResponseWriter, req *http.Request, posts []*Entry, ctx *Context) {
	url := httputil.AddProtocol(httputil.GetHost(req), "http")
	blogTitle := conf.Interface.BlogTitle
	descr := conf.Interface.BlogDescr
	author, err := ctx.Db.author()
	logger.LogIf(err)
	feed := &feeds.Feed{
		Title:       blogTitle,
		Link:        &feeds.Link{Href: url},
		Description: descr,
		Author:      &feeds.Author{Name: author.FullName, Email: author.Email},
	}
	for _, p := range posts {
		pubDate, err := time.Parse("2006-01-02", p.Date)
		if logger.LogIff(err, "Error parsing date for RSS item %q\n", p.URL) != nil {
			continue
		}
		item := feeds.Item{
			Title:       p.Title,
			Link:        &feeds.Link{Href: url + "/" + p.URL},
			Description: string(p.Body),
			Author:      &feeds.Author{Name: p.Author, Email: author.Email},
			Created:     pubDate,
		}
		feed.Items = append(feed.Items, &item)
	}
	rss, err := feed.ToRss()
	logger.LogIf(err)
	w.Write([]byte(rss))
}
Example #2
0
func prepareCommenter(req *http.Request) *Commenter {
	return &Commenter{
		Name:    req.FormValue("name"),
		Email:   req.FormValue("email"),
		Website: httputil.AddProtocol(req.FormValue("website"), "http"),
		IP:      httputil.GetIPAddress(req),
	}
}