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.se
-

SS13.se

+ ss13.se + Global stats + Latest news +

Last updated: {{.Hub.LastUpdated}}

@@ -71,7 +125,7 @@ const tmplBase string = ` Copyright © 2017 A. Svensson - Using raw data from + Raw data from Byond

@@ -82,12 +136,7 @@ const tmplBase string = ` var tmplList = map[string]string{ "index": `{{define "title"}}Index{{end}} {{define "body"}} -

Last updated: {{.Hub.LastUpdated}}

-

Current # of servers: {{.TotalServers}}

-

Current # of players: {{.Hub.Players}}

-Global stats
-Latest news
-
+

Servers

@@ -96,7 +145,7 @@ var tmplList = map[string]string{ {{range .Servers}} - + @@ -121,20 +170,22 @@ var tmplList = map[string]string{ {{define "body"}}

{{.Server.Title}}

-

Last updated: {{.Server.LastUpdated}}

-

Current players: {{.Server.Players}}

{{if .Server.SiteURL}} - Web site
+ Website {{end}} {{if .Server.ByondURL}} - Join game
+ Join game {{end}} -
-Daily history
-Weekly history
-Average per day
+

Current players: {{.Server.Players}}

+ +

Daily History

+Unable to show a pretty graph +

Weekly History

+Unable to show a pretty graph +

Average per day

+Unable to show a pretty graph {{end}} `, }
Players
{{.Players}} {{.Title}}