add .txt rendering in-template
This commit is contained in:
parent
c02423e084
commit
d02b465035
|
@ -1,6 +1,7 @@
|
|||
package gopherproxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
|
@ -125,13 +126,23 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, uri
|
|||
}
|
||||
|
||||
if res.Body != nil {
|
||||
// handle markdown
|
||||
if strings.HasSuffix(uri, ".md") {
|
||||
// handle markdown
|
||||
tpl.Execute(w, struct {
|
||||
Title string
|
||||
MdText template.HTML
|
||||
Gophermap bool
|
||||
}{uri, renderMd(res.Body), false})
|
||||
|
||||
} else if strings.HasSuffix(uri, ".txt") {
|
||||
// handle .txt files
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(res.Body)
|
||||
tpl.Execute(w, struct {
|
||||
Title string
|
||||
MdText string
|
||||
Gophermap bool
|
||||
}{uri, buf.String(), false})
|
||||
} else {
|
||||
io.Copy(w, res.Body)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue