RSS implementation
This commit is contained in:
parent
b3b6636892
commit
01b538aee2
@ -14,8 +14,12 @@ type ServerOptions struct {
|
||||
FaviconFilePath string
|
||||
AllowDBDownload bool
|
||||
RecentChanges int
|
||||
RecentChangesRSS int
|
||||
GzipCompressionLevel int
|
||||
BannedUserIPRegexes []string
|
||||
ExternalBaseURL string
|
||||
DeclareRSSLanguage string
|
||||
DeclareRSSEmail string
|
||||
}
|
||||
|
||||
func DefaultOptions() *ServerOptions {
|
||||
@ -29,7 +33,11 @@ func DefaultOptions() *ServerOptions {
|
||||
FaviconFilePath: "", // no favicon
|
||||
AllowDBDownload: true,
|
||||
RecentChanges: 20,
|
||||
RecentChangesRSS: 10,
|
||||
GzipCompressionLevel: 9,
|
||||
BannedUserIPRegexes: make([]string, 0),
|
||||
ExternalBaseURL: "/",
|
||||
DeclareRSSLanguage: "en-GB",
|
||||
DeclareRSSEmail: `nobody@example.com`,
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,10 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
this.routeIndex(w, r)
|
||||
return
|
||||
|
||||
} else if remainingPath == "rss/changes" {
|
||||
this.routeRecentChangesRSS(w, r)
|
||||
return
|
||||
|
||||
} else if remainingPath == "" {
|
||||
this.serveRedirect(w, this.opts.ExpectBaseURL+`view/`+url.QueryEscape(this.opts.DefaultPage))
|
||||
return
|
||||
|
@ -21,6 +21,7 @@ func main() {
|
||||
opts.DBFilePath = *dbPath
|
||||
opts.FaviconFilePath = *faviconPath
|
||||
opts.Timezone = time.Local.String()
|
||||
opts.ExternalBaseURL = "http://" + *bindAddr + "/"
|
||||
|
||||
ws, err := yatwiki3.NewWikiServer(opts)
|
||||
if err != nil {
|
||||
|
51
rRSS.go
Normal file
51
rRSS.go
Normal file
@ -0,0 +1,51 @@
|
||||
package yatwiki3
|
||||
|
||||
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))
|
||||
}
|
Loading…
Reference in New Issue
Block a user