diff --git a/src/tmpl_asset_build.go b/src/tmpl_asset_build.go new file mode 100644 index 0000000..ed478b5 --- /dev/null +++ b/src/tmpl_asset_build.go @@ -0,0 +1,59 @@ +// +build embed + +// Automagically generated by yaber v0.1 (https://github.com/lmas/yaber), +// please avoid editting this file as it might be regenerated again. + +package ss13 + +import ( + "bytes" + "compress/gzip" + "io/ioutil" + "os" + "strings" +) + +func Asset(path string) ([]byte, error) { + body, ok := _rawAssets[path] + if !ok { + return nil, os.ErrNotExist + } + return decompress(body) +} + +func AssetDir(dir string) (map[string][]byte, error) { + var e error + files := make(map[string][]byte) + for path, body := range _rawAssets { + if strings.HasPrefix(path, dir) { + files[path], e = decompress(body) + if e != nil { + return nil, e + } + } + } + return files, nil +} + +func decompress(data []byte) ([]byte, error) { + buf := bytes.NewBuffer(data) + gr, e := gzip.NewReader(buf) + if e != nil { + return nil, e + } + defer gr.Close() + return ioutil.ReadAll(gr) +} + +var _rawAssets = map[string][]byte{ + + "templates/base.html": []byte("\x1f\x8b\b\x00\x00\tn\x88\x00\xff\x8cTOo\xdb \x14\xbf\xf7SP&\xed\x16\xa3\xa8\u04b4u$R\xd7N\xdb-\x93\xd2\xcbN\x15\xc6\xcf\x01\xcd\x06\v\x9e\x9dF^\xbe\xfb\x00'\x8d\x93%j8\x18\xc3\xe3\xf7\xfe\xfe\xde\xeb\xfb\x02Jm\x80P\x05\xa2\x00G\xb7\xdb\x1b~\xfb\xb4x|\xfe\xfd\xeb;QXW\xf3\x1b>l$,\x1e_\r\xbf\xe9X\x03\n\"\x95p\x1epF[,'\x9f\xe9H\\i\xf3\x87(\a\xe5\x8c2\x8f\x02\xb5d\xd2{\x96[\x8b\x1e\x9dh\xb2Z\x9b,\xdcP\u281aQ\x8f\x9b\n\xbc\x02\xc0+\x94\xa4\xc7\u05c1\a\xb9\xb2\x0ee\x8bDKk\xe8\x89\xc2Rt\xf1:\v\x9f1\x1a5Vp8\xc7\xd5\xf7Y#V\x90$\xdb-\xf9K\x96\xcb\xe9\x1d\xf9\xd9\xe6\a\x14\x1b\xc18\x1b26\x1cr[lF\ua1d4\x1f\xeb\xe7FtD\x173\x1a\xf6\\8z,M/\xda\xea\xff\xcb]\xb0s.\xf6\x91\xd1\xf9\xde3\xce\u011c\xb3 \xbc\x0e\x05\xae\x03\xe7\xdf\x01\xddN&\xc7\xc0\x98H\x1f\xd0q{\xc3N&\xd7\xd8\x14\xb9mC\xd1\x1e\xe2\xf6\xae\xafDV\xc2\xfb\x19-t\xa7#_\xaf\x8dL!6\xf7\x8c\xad\xd7\xeb,\xdfXSd\xd2\xd6l%j\xf0\f^E\xd1M\x99o\x84\x84\xc4\ak\xa6wg\x12?^\u07e2\x8e\xf3V/F\xc0\xd9i\xe58\vU\x1e\x11\x82\x9d2\x82{\x90\u045f\u0108@P\x04\x13\xe9\xdd\xf7`\x8a\u04297\x87\xf6-CO\r\xed{\u0436\x03\x8f\xd4\r\xaf\x92\xb6\xdc\"\xda\xfae\x87;\xf1\xab99\x87r?/\x9e\x16\xf7\xc4X$\xbeu@R\xd1\b* \xd26\x1b\xa7W*\b\xb0-K\xb2V`H\t(\x956+\x02\xaf\x98\x91B\xa0\xc8\u0391\x81\x87\xa4\x9b}I+(\xf1B\xda\x1f\xdfl|\xfc0\xfd\xf4\xe5kh\xc3\r\b7\x8av\xbc\x1e2\xb2\xec\xc0xo\u0359\"D\x93\xbb\x86\xbc\xe8J\xb2u\xc1\x97\xa5m\x9d\x8ca\x17!\vx\x9e\x03c\xd6\xf9@\xbb\x95F\xd5\xe6\x89sU-\xc2\xf0\xf2\u04fb\x17\x0ft\xfe#\t\"g\xb2\x8b\xae\x1e\xdf5c\xbe\f\xd5\u06cf\x9aa\xbc\x04\x16\xa5y\xbd'\xc9?\x00\x00\x00\xff\xff\x01\x00\x00\xff\xff\xec\x1f]&\xe3\x05\x00\x00"), + + "templates/page_404.html": []byte("\x1f\x8b\b\x00\x00\tn\x88\x00\xffL\xcc1\x0e\xc20\fF\xe1=\xa7\xf8\xc9\u0082\xe0\x02\xa5\x97\xe0\x04V\xea\xd0J\u0176\\3TU\xeeN\u063a=\xbd\xe1;\x8e\xe0\x8f\xad\x14\x8c<3M\xec\x19\xf7\xd6R\x1a\fe\xa5m{\xe6\xc2\x12}\x8f/u\xdfQ\u0202\x16\xb9\xf5\x90k\xa0.2!f\n\x18\xbd\x19U\x1d\xbb~/\xc3\xc3\u0194\xcexU\xfd+\x9d\xfe\x01\x00\x00\xff\xff\x01\x00\x00\xff\xffC*I\xc7s\x00\x00\x00"), + + "templates/page_about.html": []byte("\x1f\x8b\b\x00\x00\tn\x88\x00\xff\xac\x93?\x8f\xdb<\f\xc6w\u007f\n\xc2\xf3!F.\xef\xf4\xc25\x90\xa2@\u0461S\xba\x17\xb4E\xc7\xc2\u0262 \xd2I\x83\xc3}\xf7R>\xb7\xb9C\x97\x0e]\x8cD\xfc\xf3<\xfcQz~V\x9aS@%\xa8'BG\xb9\x86\xdd\xcbKU\xb5\u04fe;\xf6\xbch\xdb\u062f\xaaM\xdd\x11\x84\xf2\x852LK\x0f\x8e\x9c\x1f\xac\u02812\x9cN\xfb\x03`t\x90X\xc4\xf7\xe1\x06\b=\xa9Zn&k>\xd0LQa\xe4\f:\x91\u054e\xb8\x04\xad\xb6v\t\xcf\x04\xa8\xd0\"L\x99\xc6\x0f\xf5\xa4\x9a\xfeo\x9a\xeb\xf5\xba\xebo\x1c\xddn\xe0\xb99\xe3L\xd2\xd0\x0ft\x97}#\xc9z\x8a\xa2z\x8e\xfbC\xdd},im\x83\u076emRW\x15\xb7_9\x13\xf88\xf2jl\\B\x00\xe1%\x0f\x04\x03;\xfb`4\x8bfi\xb1(\xc7\ua778\x98\xfa\u066b\u0379J\x87\x19\xa5\x11\xd9\x1f\xbe\v\xd5\xdd\xe75\xf0Vlz\xec>\xa1\"\x9c\xd6\xfeb\xc0\x1eW`\xdf\u02ac%\xb0\x88q*\xd3\xcf,\n<\xae\x14Z\xd1\xcc\xf1\u0725\xa5\x0f~h\x9b\xed\xef\x06Y\xc0\v\u02101\x95\xd2\xccs\xb5\xd6\xfc\x03D+\xef;\xa7\xa3\x81\xf9m%\xfb\x8b\xed\xf4\x0f/\x0f+C\xe1\x99\xe0\u056d\x11\xa3rj\x88{\xf2\xf1l\x8b\x0f\x81\\\xe5|\xa6Am\xffe\xd82\xfa]\xe7\xcb\b7^\xe0\xcaKp\x10\xfc\x13\x95\x8b\xf3K\x18\x9d+\u047c\t\xde\rXN\x99{3fu\xa2\x0fU1\x83\xc3@I\u07e9\x03\x96\xeb\n\xff\x81z\xe3`\x96a\xb2\x96\x0f\x90\x02\xa1\x10p\xa2\b\xf8\u05cbn\xbc\xc8b8#]\xeb\xce>\xd6ux\"]\tr,\xae\xaa5\x034\xa3\x05r9\xdcZ\xbd\xce\xfc\xf6e\x8d\xcc\xf6\x18\xea\xf2\xae~\x02\x00\x00\xff\xff\x01\x00\x00\xff\xff\xb50\xb0\xe4q\x03\x00\x00"), + + "templates/page_index.html": []byte("\x1f\x8b\b\x00\x00\tn\x88\x00\xff\xa4Vao\x9b<\x10\xfe\xde_q/o\xa5&R\x03\u06f4OY\xc2T\xad\xd2\xd6O\x9b\xd4\xee\a\xb8p$N\x89\x9d\xd9&\x19B\xfc\xf7\x9d\x81\x14HL\xba,|H\xcc\xf9\xfc\xf8\xeey\u0387\x8b\xc2\xe0z\x932\x83\xe0-\x91\u0168<\xf0\xcb\xf2\n\xe8\x99\x19\xf6\x9c\"\xf0x\xeeiT[T\u0683(eZ\u03fdz\xa6\xfa\x9d,%M\xd5c-\x95!\x84\xb0Z^CX\xd0\xf6\xbd\xb6\xa9\xbe\xa1q\fgz\xc3D8\v\x9a?\xb2\f\xbb\x81\xe1&\u0179\xf7%S\n\x85\x01)R.\x10(\x93\xdc\xc6\x19\x92\xdd?\x0f\u93b2`\v\axCM\xa1\u0163\xf6\xf0\x06\xd6\t~\x19,\x15&s/\xa8\x8fw@\xb0\x0f\xf7ei\xff\x9fl\x00e9P\x9c--{\xc7\xe1M\x02v\x0e\xd1\xfd&U\xefa\xab\xea\u0722\xfa|\x9a\x93G\xa9T~K\xa7\x05\x9a\xce\xf6\xdfPs=\x8e\xa6W\b\xb4\xacm\x9b\xf4b?C\xe1U\xfd\xa6#\xc57\x06L\xbe!)\r\xfe6\xc1\x8amYm\xf5@\xab\xc82o\x98\xe1Q\xb0\xd2\xc1\x8a\x0e\xa0\xca\xfd5\x17\xfeJW5Z9\x86\x17`u>\x8a\xa7q\xdb\x1c\xafG\xb1\x8c\xb25\x95\xe8\u06276\x16\xe7\xa3$\x13\x91\xed\v\xa3q\xd1cb\xcb\x14\x91g\f\x1dB\rs(\x8e\xb8\x8b\xb4\xbe\xd3\xd1\x14n:aL(\xe4\x9b[\x97\xeb=\x1e\xf9\xc68\xe4\xfc\xad\xba*\x1c\xb8\xdb\u03d9\u00fd\xbeV\xe8\xa9#B\xfb\xbc\x1b\x9a\xb0O\x8d<\x85\x84Q\t\xdeB\x10\xc0\xbd\x147\xa6\xb2W\x9d\xc7R\x9ei\x88d\x9a\xad\x85\x13\xa6<\x8e\xe8\xc0T~\xea\xbd^\x8f\xbc\xff\xf7\xf7\x9dqW\xc2\u045e\xedq\xbb\xa0l\u01ad\xaa\xdd\x1bU\"\xa5\xbd\x0fQ\xb9\xfe\x01\x00\x00\xff\xff\x01\x00\x00\xff\xff\xb0\x8c\x84&h\t\x00\x00"), + + "templates/page_server.html": []byte("\x1f\x8b\b\x00\x00\tn\x88\x00\xff\xecX_o\xdb6\x10\u007f\xef\xa78py\x88\x01G^\xd7\r\x03\x12Y@\xb1\x01\xed\x80\xec\x0f\x90\x16{\b\x82\x80\xb6(\x89\tEj$e\xc7S\xf5\xddw\x94dK\xb2%\xe7O\x03l\x0f#\xd0B\xbe;\xfe\ue3bf\xbb#\x91\xa2\xb0,\xcd\x04\xb5\fH\xc2h\xc84\x01\xaf,\xdf\x00.?y\x1b\x14\x85g\x98^1\xed}\xe2V\xb0\xb2\xf4g(}S\xeb),\x055fN\x16V\x02\xfe;\vYDsa\t\xb4\xdb>\u0414}\xd6\x02\xbe\x18\x1a\xb1\xdbD\xb3\b\xca\x124\x13s\"U\xa4\x84Pk\x12\\\xd2\\.\x13\x88\xd1\u059f\u0460B/\n\x1e\xc1\x16\xe5\x8a[\x87\xd2\x04\xf6\x88s\xe7dN\xda\x10v\x9b\u027e\u07cf*e\x19\x8d\xbbN\x990\xac\xebf\x91[\xab\u462f\xe07\x05\xc9\x0e\xa4\xb6\xdd!\xc9\x10\x81\x9a\x93|\x17\\Yjs\x83\xc7\xf7.\u0621\x17\x05t\x92\xfc\xc4S\xf6\x8b\xf9\xa0\x19\xb2\xa1\xe1\xbb\xef\xb74d\xc0\xc39\xa9\x8dnM\x05C\xb6\x01\xd5?oU\x14\t.\x19i\xa1}\x93Q\t\u05916'\xbf\xd7\xeasXS\x03RY0\x8cI\bs\xcde\f6a\x80`\x16\u058c\xdd{;\xe4Xl\xb2\x84/1\xf7\xdd\u05d9f\xa9Z\xb13\xc3cI\x02\u007f\xe6\\\xf4\x92q\x877\x9e\xd1\xdbg$\x94\xcb{\xa9\xd6r,\xa1\u03f5\xfa\x91\x84B\xba9\x9e\xcf_93\x96\xe3\xc7XF\x9djx\x12\r\xf2(\v\xb2%a0\xdeD\xe5\xfax\xc0\xea~<\u052a\xdc\xfa\x8e]\xc0\x169\xc0\xf0\u048c\x80\x92\xa9\xca\rC\nuG~k\x95\x12\x96g\xa7\xdd^ote9i\xb7\xe5vN\x12\x1e\xb2\u0746I'S\xb7.]\x12Uf\xb5\xfbm\xd3(\x11\x92\xa0\x8f~\xc5\u5c9a&U\x1a@c\u5d71wr\xf3gY\xd0\xf6\xd0\x1f\x82n\x98\xee4\x91o\xe9B\xb0*\u03ec\xd2U\u0134\xbc\xd4\xea\xea\xff\xb3\xc4\xe5\xdd\xe5\u01ba\x81\xd7\xcf\xc0\xb7\xba/h\f\x83\x9fr\xad\x99\xb4b\x035\xc7\xfe\f\x85\x83\x96\xef\xd1K5\r\xc6\f~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xea\x17\xf3\x8a{\xb7\x87\xec\xfd\xf8\u00f0\r\x15\xf8\x82vq\xe1\xab\xe7\xa9\xc5\xf6\xaf\x17\xc0\xc9\u0784\x9ex\v.\xc3S\xe2\xe8\xaa\x1f\xb6S\xa8_\xc0\xe6\x96\xda\xed\v}rq\x00\xd2k\xeb\x17\xa3t\xca\xe3\x18\xc6!@\xd9|\xb77h\xf7/\x10\x91R\x8e\x12\xac\xd1\u007f\x00\x00\x00\xff\xff\x01\x00\x00\xff\xff\xd3\xcc\x14I\x98\x10\x00\x00"), +} diff --git a/src/tmpl_asset_dev.go b/src/tmpl_asset_dev.go new file mode 100644 index 0000000..5eddff4 --- /dev/null +++ b/src/tmpl_asset_dev.go @@ -0,0 +1,33 @@ +// +build !embed + +// Automagically generated by yaber v0.1 (https://github.com/lmas/yaber), +// please avoid editting this file as it might be regenerated again. + +package ss13 + +import ( + "io/ioutil" + "path/filepath" +) + +func Asset(path string) ([]byte, error) { + return ioutil.ReadFile(path) +} + +func AssetDir(dir string) (map[string][]byte, error) { + tmp, e := ioutil.ReadDir(dir) + if e != nil { + return nil, e + } + + files := make(map[string][]byte) + for _, f := range tmp { + name := filepath.Join(dir, f.Name()) + body, e := ioutil.ReadFile(name) + if e != nil { + return nil, e + } + files[name] = body + } + return files, nil +} diff --git a/src/web.go b/src/web.go index 64a44dc..e48c29c 100644 --- a/src/web.go +++ b/src/web.go @@ -3,6 +3,7 @@ package ss13 import ( "html/template" "net/http" + "path/filepath" "strconv" "time" @@ -27,7 +28,7 @@ func (i *Instance) Serve(addr string) error { } }()) - // Load templates + // Custom template functions funcmap := template.FuncMap{ // safe_href let's us use URLs with custom protocols "safe_href": func(s string) template.HTMLAttr { @@ -40,7 +41,17 @@ func (i *Instance) Serve(addr string) error { return time.Now().Year() }, } - tmpl := template.Must(template.New("ServerTemplates").Funcs(funcmap).ParseGlob("templates/*")) + + // Load templates + tmpl := template.New("AllTemplates").Funcs(funcmap) + tmplfiles, err := AssetDir("templates/") + if err != nil { + panic(err) + } + for p, b := range tmplfiles { + name := filepath.Base(p) + template.Must(tmpl.New(name).Parse(string(b))) + } i.router.SetHTMLTemplate(tmpl) // Setup all URLS