Add rss feed for the news
This commit is contained in:
parent
0f81282ad9
commit
eb8acc8a5b
4 changed files with 39 additions and 3 deletions
14
news.go
14
news.go
|
@ -15,11 +15,23 @@ type newsEntry struct {
|
|||
}
|
||||
|
||||
func newsHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var data newsData
|
||||
data.S = GetStatus(w, r)
|
||||
data.S.News = true
|
||||
data.News = getNews(NUM_NEWS, 0)
|
||||
loadTemplate(w, "news", data)
|
||||
|
||||
format := r.Form["fmt"]
|
||||
if (len(format) > 0) && (format[0] == "rss") {
|
||||
loadTxtTemplate(w, "news_rss.xml", data)
|
||||
} else {
|
||||
loadTemplate(w, "news", data)
|
||||
}
|
||||
}
|
||||
|
||||
func editNewsHandler(w http.ResponseWriter, r *http.Request, sess *Session) {
|
||||
|
|
|
@ -60,7 +60,9 @@ func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
var txt_templates = txt_tmpl.Must(txt_tmpl.ParseFiles(TEMPLATE_PATH + "search_rss.xml"))
|
||||
var txt_templates = txt_tmpl.Must(txt_tmpl.ParseFiles(TEMPLATE_PATH+"search_rss.xml",
|
||||
TEMPLATE_PATH+"news_rss.xml",
|
||||
))
|
||||
|
||||
func loadTxtTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
||||
err := txt_templates.ExecuteTemplate(w, tmpl, data)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{{template "header.html" .S}}
|
||||
|
||||
<h4>News:</h4>
|
||||
<h4>News:
|
||||
<a href="/news/?fmt=rss" class="pull-right"><img src="/img/feed.png"/></a>
|
||||
</h4>
|
||||
|
||||
<dl class="dl-horizontal">
|
||||
{{range .News}}
|
||||
|
|
20
templates/news_rss.xml
Normal file
20
templates/news_rss.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
{{with .S}}
|
||||
<title>Imperial Library of Trantor - News</title>
|
||||
<description>News of the library</description>
|
||||
<link>{{.BaseURL}}/news/</link>
|
||||
{{end}}
|
||||
|
||||
{{$baseURL := .S.BaseURL}}
|
||||
{{range .News}}
|
||||
<item>
|
||||
<title>{{.Date}}</title>
|
||||
<description>{{.Text}}</description>
|
||||
<link>{{$baseURL}}/news/</link>
|
||||
</item>
|
||||
{{end}}
|
||||
|
||||
</channel>
|
||||
</rss>
|
Reference in a new issue