inline svg

This commit is contained in:
Nazar Kanaev
2020-07-20 21:48:18 +01:00
parent 98ba266921
commit 3ba13bbbcb
5 changed files with 40 additions and 32 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/nkanaev/yarr/storage"
"github.com/mmcdole/gofeed"
"net/http"
"html/template"
"encoding/json"
"encoding/xml"
"os"
@@ -20,15 +21,14 @@ import (
)
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
f, err := os.Open("template/index.html")
if err != nil {
log.Fatal(err)
}
defer f.Close()
t := template.Must(template.New("index.html").Delims("{%", "%}").Funcs(template.FuncMap{
"inline": func(svg string) template.HTML {
content, _ := ioutil.ReadFile("template/static/images/" + svg)
return template.HTML(content)
},
}).ParseFiles("template/index.html"))
rw.Header().Set("Content-Type", "text/html")
io.Copy(rw, f)
t.Execute(rw, nil)
}
func StaticHandler(rw http.ResponseWriter, req *http.Request) {

View File

@@ -148,6 +148,6 @@ func New() *http.Server {
counter: make(chan int),
}
s := &http.Server{Addr: "127.0.0.1:8000", Handler: h}
h.startJobs()
//h.startJobs()
return s
}