This commit is contained in:
parent
78bc348aae
commit
cf65859dbb
32
main.go
32
main.go
|
@ -170,6 +170,37 @@ func serveSingle(pattern string, filename string) {
|
|||
})
|
||||
}
|
||||
|
||||
// 起始页请求处理.
|
||||
func startHandler(w http.ResponseWriter, r *http.Request) {
|
||||
i18n.Load()
|
||||
|
||||
httpSession, _ := session.HTTPSession.Get(r, "wide-session")
|
||||
|
||||
if httpSession.IsNew {
|
||||
http.Redirect(w, r, "/login", http.StatusForbidden)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||
httpSession.Save(r, w)
|
||||
|
||||
username := httpSession.Values["username"].(string)
|
||||
|
||||
model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(r), "locale": i18n.GetLocale(r), "username": username}
|
||||
|
||||
t, err := template.ParseFiles("view/start.html")
|
||||
|
||||
if nil != err {
|
||||
glog.Error(err)
|
||||
http.Error(w, err.Error(), 500)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
t.Execute(w, model)
|
||||
}
|
||||
|
||||
// 主程序入口.
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(conf.Wide.MaxProcs)
|
||||
|
@ -180,6 +211,7 @@ func main() {
|
|||
http.HandleFunc("/login", handlerWrapper(loginHandler))
|
||||
http.HandleFunc("/logout", handlerWrapper(logoutHandler))
|
||||
http.HandleFunc("/", handlerWrapper(indexHandler))
|
||||
http.HandleFunc("/start", handlerWrapper(startHandler))
|
||||
|
||||
// 静态资源
|
||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#startPage .details {
|
||||
width: 40%;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#startPage .news {
|
||||
width: 60%;
|
||||
float: left;
|
||||
}
|
|
@ -82,7 +82,43 @@ var editors = {
|
|||
editors.tabs.add({
|
||||
id: "startPage",
|
||||
title: '<span title="' + config.label.initialise + '">' + config.label.initialise + '</span>',
|
||||
content: '<textarea id="editor"></textarea>'
|
||||
content: '<div id="startPage"></div>'
|
||||
});
|
||||
|
||||
$("#startPage").load('/start');
|
||||
$.ajax({
|
||||
url: "http://symphony.b3log.org/apis/articles?tags=wide,golang&p=1&size=30",
|
||||
type: "GET",
|
||||
dataType: "jsonp",
|
||||
jsonp: "callback",
|
||||
error: function () {
|
||||
$("#startPage").html("Loading B3log Announcement failed :-(");
|
||||
},
|
||||
success: function (data, textStatus) {
|
||||
var articles = data.articles;
|
||||
if (0 === articles.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 按 size = 30 取,但只保留最多 10 篇
|
||||
var length = articles.length;
|
||||
if (length > 10) {
|
||||
length = 10;
|
||||
}
|
||||
|
||||
var listHTML = "<ul>";
|
||||
for (var i = 0; i < length; i++) {
|
||||
var article = articles[i];
|
||||
var articleLiHtml = "<li>"
|
||||
+ "<a target='_blank' href='" + article.articlePermalink + "'>"
|
||||
+ article.articleTitle + "</a> <span class='date'>" + article.articleCreateTime;
|
||||
+"</span></li>"
|
||||
listHTML += articleLiHtml;
|
||||
}
|
||||
listHTML += "</ul>";
|
||||
|
||||
$("#startPage .news").html(listHTML);
|
||||
}
|
||||
});
|
||||
},
|
||||
getCurrentId: function () {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/base.css?{{.conf.StaticResourceVersion}}">
|
||||
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/wide.css?{{.conf.StaticResourceVersion}}">
|
||||
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/side.css?{{.conf.StaticResourceVersion}}">
|
||||
<link rel="stylesheet" href="{{.conf.StaticServer}}/static/css/start.css?{{.conf.StaticResourceVersion}}">
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
</head>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<div class="fn-clear">
|
||||
<ul class="details">
|
||||
<li>
|
||||
用户名{{.username}}
|
||||
</li>
|
||||
<li>
|
||||
用户指南 http://88250.gitbooks.io/wide-user-guide
|
||||
</li>
|
||||
<li>
|
||||
开发指南 http://88250.gitbooks.io/wide-user-guide
|
||||
</li>
|
||||
<li>
|
||||
Wide 信息
|
||||
版本 {{.ver}}
|
||||
开发团队
|
||||
</li>
|
||||
<li>
|
||||
捐赠 http://b3log.org/donate.html
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="news">
|
||||
aaa
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue