Add "hmarkdown" format which is more article like
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
b8910f9aa6
commit
692a065f82
12
main.go
12
main.go
|
@ -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, "# ")
|
||||
|
|
Loading…
Reference in New Issue
Block a user