parent
94d80bae1a
commit
3b8cb3385b
|
@ -63,27 +63,37 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// try to load file
|
// try to load file
|
||||||
code := conf.HelloWorld
|
code := conf.HelloWorld
|
||||||
|
fileName := "8b7cc38b4c12e6fde5c4d15a4f2f32e5.go" // MD5 of HelloWorld.go
|
||||||
if strings.HasSuffix(r.RequestURI, ".go") {
|
if strings.HasSuffix(r.RequestURI, ".go") {
|
||||||
fileName := r.RequestURI[len("/playground/"):]
|
fileNameArg := r.RequestURI[len("/playground/"):]
|
||||||
filePath := filepath.Clean(conf.Wide.Playground + "/" + fileName)
|
filePath := filepath.Clean(conf.Wide.Playground + "/" + fileNameArg)
|
||||||
|
|
||||||
bytes, err := ioutil.ReadFile(filePath)
|
bytes, err := ioutil.ReadFile(filePath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logger.Warn(err)
|
logger.Warn(err)
|
||||||
|
} else {
|
||||||
|
code = string(bytes)
|
||||||
|
fileName = fileNameArg
|
||||||
}
|
}
|
||||||
|
|
||||||
code = string(bytes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query := r.URL.Query()
|
||||||
embed := false
|
embed := false
|
||||||
embedArg, ok := r.URL.Query()["embed"]
|
embedArg, ok := query["embed"]
|
||||||
if ok && "true" == embedArg[0] {
|
if ok && "true" == embedArg[0] {
|
||||||
embed = true
|
embed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disqus := false
|
||||||
|
disqusArg, ok := query["disqus"]
|
||||||
|
if ok && "true" == disqusArg[0] {
|
||||||
|
disqus = true
|
||||||
|
}
|
||||||
|
|
||||||
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(locale), "locale": locale,
|
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(locale), "locale": locale,
|
||||||
"session": wideSession, "pathSeparator": conf.PathSeparator, "codeMirrorVer": conf.CodeMirrorVer,
|
"session": wideSession, "pathSeparator": conf.PathSeparator, "codeMirrorVer": conf.CodeMirrorVer,
|
||||||
"code": template.HTML(code), "ver": conf.WideVersion, "year": time.Now().Year(), "embed": embed}
|
"code": template.HTML(code), "ver": conf.WideVersion, "year": time.Now().Year(),
|
||||||
|
"embed": embed, "disqus": disqus, "fileName": fileName}
|
||||||
|
|
||||||
wideSessions := session.WideSessions.GetByUsername(username)
|
wideSessions := session.WideSessions.GetByUsername(username)
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,19 @@
|
||||||
</div>
|
</div>
|
||||||
<textarea id="output" rows="20" readonly="readonly" ></textarea>
|
<textarea id="output" rows="20" readonly="readonly" ></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
{{if .disqus}}
|
||||||
|
<div id="disqus_thread"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var disqus_shortname = 'wide-playground';
|
||||||
|
var disqus_identifier = {{.fileName}};
|
||||||
|
var disqus_url = window.location.protocol + "//" + {{.conf.Server}} + {{.conf.Context}} + "/playground/" + {{.fileName}}
|
||||||
|
(function() {
|
||||||
|
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
|
||||||
|
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
|
||||||
|
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
||||||
|
})();</script>
|
||||||
|
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
|
||||||
|
{{end}}
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
Ver {{.ver}}, © {{.year}} <a rel="copyright" href="http://b3log.org" target="_blank">B3LOG.ORG</a>
|
Ver {{.ver}}, © {{.year}} <a rel="copyright" href="http://b3log.org" target="_blank">B3LOG.ORG</a>
|
||||||
|
@ -76,6 +89,7 @@
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
"context": "{{.conf.Context}}",
|
"context": "{{.conf.Context}}",
|
||||||
|
"server": "{{.conf.Server}}",
|
||||||
"staticServer": "{{.conf.StaticServer}}",
|
"staticServer": "{{.conf.StaticServer}}",
|
||||||
"channel": "{{.conf.Channel}}",
|
"channel": "{{.conf.Channel}}",
|
||||||
"wideSessionId": "{{.session.ID}}",
|
"wideSessionId": "{{.session.ID}}",
|
||||||
|
|
Loading…
Reference in New Issue