diff --git a/main.go b/main.go index 3e37e08..0cc1408 100644 --- a/main.go +++ b/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")))) diff --git a/static/css/start.css b/static/css/start.css new file mode 100644 index 0000000..26ac9dc --- /dev/null +++ b/static/css/start.css @@ -0,0 +1,9 @@ +#startPage .details { + width: 40%; + float: left; +} + +#startPage .news { + width: 60%; + float: left; +} \ No newline at end of file diff --git a/static/js/editors.js b/static/js/editors.js index c055403..490d2ce 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -82,7 +82,43 @@ var editors = { editors.tabs.add({ id: "startPage", title: '' + config.label.initialise + '', - content: '' + content: '
' + }); + + $("#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 = ""; + + $("#startPage .news").html(listHTML); + } }); }, getCurrentId: function () { diff --git a/view/index.html b/view/index.html index 062700f..e7cd8a7 100644 --- a/view/index.html +++ b/view/index.html @@ -15,6 +15,7 @@ + diff --git a/view/start.html b/view/start.html new file mode 100644 index 0000000..daaefba --- /dev/null +++ b/view/start.html @@ -0,0 +1,25 @@ +
+ + +
+ aaa +
+