|
@@ -2,6 +2,10 @@ package figtree
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "path"
|
|
|
+ "html/template"
|
|
|
+ "strings"
|
|
|
+ "io/ioutil"
|
|
|
)
|
|
|
|
|
|
type Fig struct {
|
|
@@ -18,9 +22,28 @@ type FancyFig struct {
|
|
|
Path string
|
|
|
Desc string
|
|
|
Birth string
|
|
|
+ View template.HTML
|
|
|
}
|
|
|
|
|
|
func (f Fig) Fancy() FancyFig {
|
|
|
path := fmt.Sprintf("%s%s/%s.%s", FIGS, f.Type, f.Id, f.Ext)
|
|
|
- return FancyFig{ f.Name, path, f.Desc, f.Birth }
|
|
|
+ view := tryDispHtml(f)
|
|
|
+ return FancyFig{ f.Name, path, f.Desc, f.Birth, view}
|
|
|
+}
|
|
|
+
|
|
|
+func tryDispHtml(fig Fig) template.HTML {
|
|
|
+ figtype := strings.ToLower(fig.Ext)
|
|
|
+ figpath := fig.Type + "/" + fig.Id + "." + fig.Ext
|
|
|
+ switch figtype {
|
|
|
+ case "png", "jpg", "jpeg", "gif":
|
|
|
+ return template.HTML("<img src=/imagination/" + figpath + ">")
|
|
|
+ case "txt", "org":
|
|
|
+ contents, err := ioutil.ReadFile(path.Join(FIGS, figpath))
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ return template.HTML(fmt.Sprintf("<blockquote><pre>%s</pre></blockquote>", contents))
|
|
|
+ default:
|
|
|
+ return template.HTML("<p>somethin good</p>")
|
|
|
+ }
|
|
|
}
|