Add "hmarkdown" format which is more article like
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2020-11-16 22:48:54 +01:00
parent b8910f9aa6
commit 692a065f82

12
main.go
View File

@ -615,7 +615,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
format = "html"
}
if !(format == "html" || format == "markdown" || format == "json" || format == "metakv") {
if !(format == "html" || format == "markdown" || format == "hmarkdown" || format == "json" || format == "metakv") {
http.Error(w, "unknown format", http.StatusBadRequest)
}
@ -678,6 +678,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
builder := strings.Builder{}
if format == "markdown" {
for _, item := range listItems {
lines := strings.Split(item.Text, "\n")
if len(lines) > 1 {
@ -707,6 +708,13 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
builder.WriteByte('\n')
}
}
} else if format == "hmarkdown" {
for _, item := range listItems {
builder.WriteString(item.Text)
builder.WriteByte('\n')
builder.WriteByte('\n')
}
}
pageText = builder.String()
}
@ -742,7 +750,7 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// http.Error(w, err.Error(), 500)
return
}
} else if format == "markdown" {
} else if format == "markdown" || format == "hmarkdown" {
w.Header().Set("Content-Type", "text/markdown")
w.Header().Set("Cache-Control", "public, max-age=600")
_, err = io.WriteString(w, "# ")