35 lines
884 B
Go
35 lines
884 B
Go
|
package yatwiki3
|
||
|
|
||
|
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 {
|
||
|
content += `<li><a href="` + template.HTMLEscapeString(this.opts.ExpectBaseURL+`view/`+url.QueryEscape(title)) + `">` + template.HTMLEscapeString(title) + `</a></li>`
|
||
|
}
|
||
|
content += `</ul>`
|
||
|
|
||
|
pto := DefaultPageTemplateOptions(this.opts)
|
||
|
pto.CurrentPageName = "Index"
|
||
|
pto.Content = template.HTML(content)
|
||
|
this.servePageResponse(w, r, pto)
|
||
|
return
|
||
|
}
|