From 51685c55d9bec117dff3fad63e6d8cfada3b0e28 Mon Sep 17 00:00:00 2001
From: "A. Svensson"
Date: Tue, 22 Aug 2017 21:24:19 +0200
Subject: [PATCH] Adds proper styling I don't have to be embarassed about
---
handlers.go | 9 +++---
main.go | 4 ++-
templates.go | 85 +++++++++++++++++++++++++++++++++++++++++-----------
3 files changed, 75 insertions(+), 23 deletions(-)
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
@@ -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