42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package yatwiki
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
func (this *WikiServer) routeView(w http.ResponseWriter, r *http.Request, articleTitle string) {
|
|
fmt.Printf("%#v\n", articleTitle)
|
|
a, err := this.db.GetLatestVersion(articleTitle)
|
|
if err != nil {
|
|
|
|
if err == sql.ErrNoRows {
|
|
// Yatwiki2 always required a trailing slash at the end of the URL
|
|
// If this was an old link, it might not be present.
|
|
// Redirect if possible
|
|
if len(articleTitle) > 0 && articleTitle[len(articleTitle)-1] == '/' {
|
|
this.serveRedirect(w, this.opts.ExpectBaseURL+"view/"+url.PathEscape(articleTitle[0:len(articleTitle)-1]))
|
|
return
|
|
}
|
|
|
|
this.serveErrorHTMLMessage(w, this.noSuchArticleError(articleTitle))
|
|
return
|
|
}
|
|
this.serveErrorMessage(w, err)
|
|
return
|
|
}
|
|
|
|
pto := DefaultPageTemplateOptions(this.opts)
|
|
pto.CurrentPageName = articleTitle
|
|
pto.CurrentPageIsArticle = true
|
|
|
|
bcr := NewBBCodeRenderer(this.opts.ExpectBaseURL)
|
|
pto.Content = bcr.RenderHTML(string(a.Body))
|
|
pto.LoadCodeResources = bcr.CodePresent
|
|
|
|
this.servePageResponse(w, r, pto)
|
|
return
|
|
}
|