2017-07-12 06:43:11 +00:00
|
|
|
package yatwiki
|
2017-07-09 01:26:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (this *WikiServer) routeIndex(w http.ResponseWriter, r *http.Request) {
|
|
|
|
titles, err := this.db.ListTitles()
|
|
|
|
if err != nil {
|
|
|
|
this.serveInternalError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
totalRevs, err := this.db.TotalRevisions()
|
|
|
|
if err != nil {
|
|
|
|
this.serveInternalError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
content := fmt.Sprintf(`<h2>Article Index</h2><br><em>There are %d edits to %d pages.</em><br><br><ul>`, totalRevs, len(titles))
|
|
|
|
for _, title := range titles {
|
2017-08-13 05:51:44 +00:00
|
|
|
content += `<li><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.PathEscape(title)) + `">` + template.HTMLEscapeString(title) + `</a></li>`
|
2017-07-09 01:26:26 +00:00
|
|
|
}
|
|
|
|
content += `</ul>`
|
|
|
|
|
|
|
|
pto := DefaultPageTemplateOptions(this.opts)
|
|
|
|
pto.CurrentPageName = "Index"
|
|
|
|
pto.Content = template.HTML(content)
|
|
|
|
this.servePageResponse(w, r, pto)
|
|
|
|
return
|
|
|
|
}
|