diff --git a/handlers.go b/handlers.go index 780af03..c02c907 100644 --- a/handlers.go +++ b/handlers.go @@ -19,22 +19,20 @@ func (a *App) pageIndex(w http.ResponseWriter, r *http.Request, vars handlerVars break } } - var hub ServerEntry if index > -1 { - hub = servers[index] servers = append(servers[:index], servers[index+1:]...) } return a.templates["index"].Execute(w, map[string]interface{}{ - "Servers": servers, - "Hub": hub, - "TotalServers": len(servers), + "Servers": servers, + "Hub": a.hub, }) } func (a *App) pageNews(w http.ResponseWriter, r *http.Request, vars handlerVars) error { return a.templates["news"].Execute(w, map[string]interface{}{ "Reddit": a.news, + "Hub": a.hub, }) } @@ -55,6 +53,7 @@ func (a *App) pageServer(w http.ResponseWriter, r *http.Request, vars handlerVar return a.templates["server"].Execute(w, map[string]interface{}{ "Server": server, + "Hub": a.hub, }) } diff --git a/main.go b/main.go index 4c09928..4e13d6f 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ type App struct { store Storage templates map[string]*template.Template news []*rss.Item + hub ServerEntry // TODO: probably needs to be protected with a lock } func New(c Conf) (*App, error) { @@ -174,7 +175,7 @@ func (a *App) makeHubEntry(t time.Time, servers []ServerEntry) ServerEntry { totalPlayers += s.Players } - return ServerEntry{ + a.hub = ServerEntry{ ID: makeID(internalServerTitle), Title: internalServerTitle, SiteURL: "", @@ -182,4 +183,5 @@ func (a *App) makeHubEntry(t time.Time, servers []ServerEntry) ServerEntry { Time: t, Players: totalPlayers, } + return a.hub } diff --git a/templates.go b/templates.go index a9b6e6d..ed75d5f 100644 --- a/templates.go +++ b/templates.go @@ -28,6 +28,8 @@ func parseTemplate(src ...string) (*template.Template, error) { return t, nil } +// Using the awesome style from http://bettermotherfuckingwebsite.com/ + const tmplBase string = `
@@ -36,24 +38,76 @@ const tmplBase string = ` {{block "title" .}}NO TITLE{{end}} | ss13.seLast updated: {{.Hub.LastUpdated}}
Last updated: {{.Hub.LastUpdated}}
-Current # of servers: {{.TotalServers}}
-Current # of players: {{.Hub.Players}}
-Global stats| Players | @@ -96,7 +145,7 @@ var tmplList = map[string]string{|
| {{.Players}} | {{.Title}} |