42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
// "html"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"git.32bit.cafe/yequari/rss-gen/feed"
|
|
)
|
|
|
|
func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
|
|
app.renderPage(w, http.StatusOK, "home.tmpl.html", nil)
|
|
}
|
|
|
|
func (app *application) generateRss(w http.ResponseWriter, r *http.Request) {
|
|
q := r.URL.Query()
|
|
siteName := q.Get("site-name")
|
|
siteUrl := q.Get("site-url")
|
|
siteDesc := q.Get("site-description")
|
|
pageUrls := q.Get("page-urls")
|
|
pages := strings.Split(pageUrls, "\n")
|
|
for i := range pages {
|
|
pages[i] = strings.TrimSpace(pages[i])
|
|
}
|
|
|
|
feedInfo, err := feed.NewFeedInfo(siteName, siteUrl, siteDesc, "", pages...)
|
|
if err != nil {
|
|
app.errorLog.Printf("Error generating feed: %s\n", err.Error())
|
|
return
|
|
}
|
|
|
|
feed := feedInfo.GenerateRSS()
|
|
data := newTemplateData(r)
|
|
data.Feeds = append(data.Feeds, feed)
|
|
app.renderElem(w, http.StatusOK, "feed-output.tmpl.html", data)
|
|
}
|