Compare commits

...

3 Commits

Author SHA1 Message Date
Ben Harris 735de69f98 fix import path 2018-11-22 10:16:34 -05:00
Ben Harris 1bf0a3dacb
fix .txt 2018-11-07 21:23:07 -05:00
Ben Harris d02b465035
add .txt rendering in-template 2018-11-07 20:51:38 -05:00
3 changed files with 18 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import (
"flag"
"log"
"tildegit.org/team/gopherproxy"
"tildegit.org/tildeverse/gopherproxy"
)
var (

View File

@ -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)
}

View File

@ -17,7 +17,9 @@ var tpltext = `<!doctype html>
{{end}}
</pre>
{{else}}
{{if .Pre}}<pre>{{end}}
{{.MdText}}
{{if .Pre}}</pre>{{end}}
{{end}}
</section>
</div>