Add export format: "markdown"
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
20e454d4a3
commit
524b0140b5
61
main.go
61
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -441,6 +442,15 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
format := r.URL.Query().Get("format")
|
||||||
|
if format == "" {
|
||||||
|
format = "html"
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(format == "html" || format == "markdown") {
|
||||||
|
http.Error(w, "unknown format", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
page := r.URL.Path[1:]
|
page := r.URL.Path[1:]
|
||||||
if page == "" {
|
if page == "" {
|
||||||
page = "Home"
|
page = "Home"
|
||||||
|
@ -501,32 +511,37 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
pageText = builder.String()
|
pageText = builder.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
pageText = renderLinks(pageText)
|
if format == "html" {
|
||||||
|
pageText = renderLinks(pageText)
|
||||||
|
pageText = renderMarkdown2(pageText)
|
||||||
|
|
||||||
pageText = renderMarkdown2(pageText)
|
pageBase := getPageBase()
|
||||||
|
data := indexPage{
|
||||||
|
pageBaseInfo: pageBase,
|
||||||
|
Session: sess,
|
||||||
|
Title: cleanTitle(page),
|
||||||
|
Content: template.HTML(pageText),
|
||||||
|
Name: page,
|
||||||
|
Backrefs: mpPage.Refs,
|
||||||
|
}
|
||||||
|
|
||||||
pageBase := getPageBase()
|
t, err := template.ParseFiles("templates/layout.html", "templates/view.html")
|
||||||
data := indexPage{
|
if err != nil {
|
||||||
pageBaseInfo: pageBase,
|
http.Error(w, err.Error(), 500)
|
||||||
Session: sess,
|
return
|
||||||
Title: cleanTitle(page),
|
}
|
||||||
Content: template.HTML(pageText),
|
err = t.Execute(w, data)
|
||||||
Name: page,
|
if err != nil {
|
||||||
Backrefs: mpPage.Refs,
|
log.Println(err)
|
||||||
|
// http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else if format == "markdown" {
|
||||||
|
_, err = io.WriteString(w, "# ")
|
||||||
|
_, err = io.WriteString(w, cleanTitle(page))
|
||||||
|
_, err = io.WriteString(w, "\n\n")
|
||||||
|
_, err = io.WriteString(w, pageText)
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := template.ParseFiles("templates/layout.html", "templates/view.html")
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = t.Execute(w, data)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
// http.Error(w, err.Error(), 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderLinks(pageText string) string {
|
func renderLinks(pageText string) string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user