Use egon templating for the index page
This commit is contained in:
parent
e5057cf227
commit
240392dcae
@ -27,7 +27,6 @@
|
|||||||
"gulp-concat": "^2.6.0",
|
"gulp-concat": "^2.6.0",
|
||||||
"gulp-cssnano": "^2.1.1",
|
"gulp-cssnano": "^2.1.1",
|
||||||
"gulp-gzip": "1.2.0",
|
"gulp-gzip": "1.2.0",
|
||||||
"gulp-htmlmin": "^1.3.0",
|
|
||||||
"gulp-util": "^3.0.7",
|
"gulp-util": "^3.0.7",
|
||||||
"ify-loader": "^1.0.3",
|
"ify-loader": "^1.0.3",
|
||||||
"react-transform-catch-errors": "^1.0.2",
|
"react-transform-catch-errors": "^1.0.2",
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
|
|
||||||
<title>Dispatch</title>
|
|
||||||
|
|
||||||
<link href="/bundle.css" rel="stylesheet">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script id="env" type="application/json"></script>
|
|
||||||
<script src="/bundle.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
20
server/index.egon
Normal file
20
server/index.egon
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<%! data *indexData, cssPath, jsPath string %>
|
||||||
|
|
||||||
|
<%% import "encoding/json" %%>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
|
<title>Dispatch</title>
|
||||||
|
|
||||||
|
<link href="/<%== cssPath %>" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script id="env" type="application/json"><% json.NewEncoder(w).Encode(data) %></script>
|
||||||
|
<script src="/<%== jsPath %>"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
19
server/index.egon.go
Normal file
19
server/index.egon.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Generated by egon.
|
||||||
|
// 🚫Edit at your own risk.
|
||||||
|
|
||||||
|
package server
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
func IndexTemplate(w io.Writer, data *indexData, cssPath, jsPath string) error {
|
||||||
|
io.WriteString(w, "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Dispatch</title><link href=\"/")
|
||||||
|
io.WriteString(w, cssPath )
|
||||||
|
io.WriteString(w, "\" rel=\"stylesheet\"></head><body><div id=\"root\"></div><script id=\"env\" type=\"application/json\">")
|
||||||
|
json.NewEncoder(w).Encode(data)
|
||||||
|
io.WriteString(w, "</script><script src=\"/")
|
||||||
|
io.WriteString(w, jsPath )
|
||||||
|
io.WriteString(w, "\"></script></body></html>")
|
||||||
|
return nil
|
||||||
|
}
|
@ -1,25 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
index_0 = []byte(`<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Dispatch</title><link href=/`)
|
|
||||||
index_1 = []byte(` rel=stylesheet></head><body><div id=root></div><script id=env type=application/json>`)
|
|
||||||
index_2 = []byte(`</script><script src=/`)
|
|
||||||
index_3 = []byte(`></script></body></html>`)
|
|
||||||
)
|
|
||||||
|
|
||||||
func renderIndex(w io.Writer, data interface{}) {
|
|
||||||
w.Write(index_0)
|
|
||||||
w.Write([]byte(files[1].Path))
|
|
||||||
w.Write(index_1)
|
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(data)
|
|
||||||
|
|
||||||
w.Write(index_2)
|
|
||||||
w.Write([]byte(files[0].Path))
|
|
||||||
w.Write(index_3)
|
|
||||||
}
|
|
@ -159,10 +159,10 @@ func serveIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Encoding", "gzip")
|
w.Header().Set("Content-Encoding", "gzip")
|
||||||
|
|
||||||
gzw := gzip.NewWriter(w)
|
gzw := gzip.NewWriter(w)
|
||||||
renderIndex(gzw, getIndexData(r, session))
|
IndexTemplate(gzw, getIndexData(r, session), files[1].Path, files[0].Path)
|
||||||
gzw.Close()
|
gzw.Close()
|
||||||
} else {
|
} else {
|
||||||
renderIndex(w, getIndexData(r, session))
|
IndexTemplate(w, getIndexData(r, session), files[1].Path, files[0].Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user