yatwiki/rRSS.go

52 lines
2.1 KiB
Go
Raw Normal View History

2017-07-12 06:43:11 +00:00
package yatwiki
2017-07-11 07:08:22 +00:00
import (
"fmt"
"html/template"
"net/http"
"net/url"
"time"
)
func (this *WikiServer) routeRecentChangesRSS(w http.ResponseWriter, r *http.Request) {
recents, err := this.db.GetRecentChanges(0, this.opts.RecentChangesRSS)
if err != nil {
this.serveInternalError(w, r, err)
return
}
content := `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>` + template.HTMLEscapeString(this.opts.PageTitle) + `</title>
<link>` + template.HTMLEscapeString(this.opts.ExternalBaseURL) + `</link>
<description>` + template.HTMLEscapeString(this.opts.PageTitle) + `</description>
<language>` + template.HTMLEscapeString(this.opts.DeclareRSSLanguage) + `</language>
<atom:link href="` + template.HTMLEscapeString(this.opts.ExternalBaseURL+`rss/changes`) + `" rel="self" type="application/rss+xml" />
`
for _, a := range recents {
content += `
<item>
<title>` + template.HTMLEscapeString(a.Title+` (r`+fmt.Sprintf("%d", a.ID)+`)`) + `</title>
<link>` + template.HTMLEscapeString(this.opts.ExternalBaseURL+`archive/`+fmt.Sprintf("%d", a.ID)) + `</link>
<guid>` + template.HTMLEscapeString(this.opts.ExternalBaseURL+`archive/`+fmt.Sprintf("%d", a.ID)) + `</guid>
<author>` + template.HTMLEscapeString(this.opts.DeclareRSSEmail+` (`+this.opts.PageTitle+` `+a.Author+`)`) + `</author>
<pubDate>` + template.HTMLEscapeString(time.Unix(a.Modified, 0).In(this.loc).Format(time.RFC1123Z)) + `</pubDate>
<description>` + template.HTMLEscapeString(`
<a href="`+template.HTMLEscapeString(this.opts.ExternalBaseURL+`view/`+url.QueryEscape(a.Title))+`">latest version</a>
|
<a href="`+template.HTMLEscapeString(this.opts.ExternalBaseURL+`archive/`+fmt.Sprintf("%d", a.ID))+`">revision `+fmt.Sprintf("%d", a.ID)+`</a>
|
<a href="`+template.HTMLEscapeString(this.opts.ExternalBaseURL+`diff/parent/`+fmt.Sprintf("%d", a.ID))+`">diff to previous</a>
`) + `</description>
</item>
`
}
content += `
</channel>
</rss>`
w.Header().Set(`Content-Type`, `application/rss+xml`)
w.Write([]byte(content))
}