forked from tildeverse/gopherproxy
Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Ben Harris | 735de69f98 | |
Ben Harris | 1bf0a3dacb | |
Ben Harris | d02b465035 |
|
@ -4,7 +4,7 @@ import (
|
|||
"flag"
|
||||
"log"
|
||||
|
||||
"tildegit.org/team/gopherproxy"
|
||||
"tildegit.org/tildeverse/gopherproxy"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package gopherproxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
|
@ -125,13 +126,25 @@ 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})
|
||||
Pre bool
|
||||
}{uri, renderMd(res.Body), false, 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
|
||||
Pre bool
|
||||
}{uri, buf.String(), false, true})
|
||||
} else {
|
||||
io.Copy(w, res.Body)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ var tpltext = `<!doctype html>
|
|||
{{end}}
|
||||
</pre>
|
||||
{{else}}
|
||||
{{if .Pre}}<pre>{{end}}
|
||||
{{.MdText}}
|
||||
{{if .Pre}}</pre>{{end}}
|
||||
{{end}}
|
||||
</section>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue