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
56
main.go
56
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,33 +678,41 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
builder := strings.Builder{}
|
||||
for _, item := range listItems {
|
||||
lines := strings.Split(item.Text, "\n")
|
||||
if len(lines) > 1 {
|
||||
first := true
|
||||
for _, line := range lines {
|
||||
if first {
|
||||
builder.WriteString(strings.Repeat(" ", item.Indented))
|
||||
builder.WriteString("* ")
|
||||
builder.WriteString(line)
|
||||
builder.WriteByte('\n')
|
||||
first = false
|
||||
} else {
|
||||
builder.WriteString(strings.Repeat(" ", item.Indented+1))
|
||||
builder.WriteString(line)
|
||||
builder.WriteByte('\n')
|
||||
if format == "markdown" {
|
||||
for _, item := range listItems {
|
||||
lines := strings.Split(item.Text, "\n")
|
||||
if len(lines) > 1 {
|
||||
first := true
|
||||
for _, line := range lines {
|
||||
if first {
|
||||
builder.WriteString(strings.Repeat(" ", item.Indented))
|
||||
builder.WriteString("* ")
|
||||
builder.WriteString(line)
|
||||
builder.WriteByte('\n')
|
||||
first = false
|
||||
} else {
|
||||
builder.WriteString(strings.Repeat(" ", item.Indented+1))
|
||||
builder.WriteString(line)
|
||||
builder.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if matches := metaKV.FindStringSubmatch(item.Text); matches != nil {
|
||||
if matches[1] == "Title" {
|
||||
title = matches[2]
|
||||
} else {
|
||||
if matches := metaKV.FindStringSubmatch(item.Text); matches != nil {
|
||||
if matches[1] == "Title" {
|
||||
title = matches[2]
|
||||
}
|
||||
}
|
||||
builder.WriteString(strings.Repeat(" ", item.Indented))
|
||||
builder.WriteString("* ")
|
||||
builder.WriteString(item.Text)
|
||||
builder.WriteByte('\n')
|
||||
}
|
||||
builder.WriteString(strings.Repeat(" ", item.Indented))
|
||||
builder.WriteString("* ")
|
||||
}
|
||||
} 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