disqus integration
This commit is contained in:
Liang Ding 2015-02-21 14:37:04 +08:00
parent 94d80bae1a
commit 3b8cb3385b
2 changed files with 30 additions and 6 deletions

View File

@ -63,27 +63,37 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
// try to load file
code := conf.HelloWorld
fileName := "8b7cc38b4c12e6fde5c4d15a4f2f32e5.go" // MD5 of HelloWorld.go
if strings.HasSuffix(r.RequestURI, ".go") {
fileName := r.RequestURI[len("/playground/"):]
filePath := filepath.Clean(conf.Wide.Playground + "/" + fileName)
fileNameArg := r.RequestURI[len("/playground/"):]
filePath := filepath.Clean(conf.Wide.Playground + "/" + fileNameArg)
bytes, err := ioutil.ReadFile(filePath)
if nil != err {
logger.Warn(err)
} else {
code = string(bytes)
fileName = fileNameArg
}
code = string(bytes)
}
query := r.URL.Query()
embed := false
embedArg, ok := r.URL.Query()["embed"]
embedArg, ok := query["embed"]
if ok && "true" == embedArg[0] {
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,
"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)

View File

@ -65,6 +65,19 @@
</div>
<textarea id="output" rows="20" readonly="readonly" ></textarea>
</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="wrapper">
Ver {{.ver}}, &copy; {{.year}} <a rel="copyright" href="http://b3log.org" target="_blank">B3LOG.ORG</a>
@ -76,6 +89,7 @@
<script>
var config = {
"context": "{{.conf.Context}}",
"server": "{{.conf.Server}}",
"staticServer": "{{.conf.StaticServer}}",
"channel": "{{.conf.Channel}}",
"wideSessionId": "{{.session.ID}}",