From feb228c1fc35aae543d369012994eac7a1dca90f Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Thu, 27 Mar 2014 23:48:11 +0100 Subject: Homepage done --- main.go | 3 +- pages.go | 22 +++++++++++-- static/chat.css | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ static/home.css | 38 ++++++++++++++++++++++ static/style.css | 97 -------------------------------------------------------- tpls/chat.html | 2 +- tpls/home.html | 34 ++++++++++++++++++-- 7 files changed, 189 insertions(+), 104 deletions(-) create mode 100644 static/chat.css create mode 100644 static/home.css delete mode 100644 static/style.css diff --git a/main.go b/main.go index 33119e4..43c5561 100644 --- a/main.go +++ b/main.go @@ -31,8 +31,9 @@ func main() { r := mux.NewRouter() r.HandleFunc("/", Home) r.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(*staticpath)))) - r.HandleFunc("/chat/{chatroom:.+}/", Chatpage) r.HandleFunc("/chat/{chatroom:.+}/socket", AcceptWebSock) + r.HandleFunc("/chat/{chatroom:.+}/", Chatpage) + r.HandleFunc("/chat/{chatroom:.+}", Chatpage) http.Handle("/", r) http.ListenAndServe(*laddr, nil) } diff --git a/pages.go b/pages.go index 886f1d6..ebe284a 100644 --- a/pages.go +++ b/pages.go @@ -3,8 +3,10 @@ package main import ( "github.com/gorilla/mux" "html/template" + "math/rand" "net/http" "path" + "strings" ) var ( @@ -15,16 +17,32 @@ type ChatpageData struct { Websock, Roomname string } +type HomeData struct { + RandomChat string +} + +var randroomAlphabet = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLNOPQRSTUVWXYZ") + +const randroomLen = 10 + +func randomRoom() string { + name := make([]rune, randroomLen) + for i := 0; i < randroomLen; i++ { + name[i] = randroomAlphabet[rand.Intn(len(randroomAlphabet))] + } + return string(name) +} + func PrepTemplates() { TplHome = template.Must(template.ParseFiles(path.Join(*tplpath, "home.html"))) TplChat = template.Must(template.ParseFiles(path.Join(*tplpath, "chat.html"))) } func Home(rw http.ResponseWriter, req *http.Request) { - TplHome.Execute(rw, nil) // TODO: Should we log the error? + TplHome.Execute(rw, HomeData{randomRoom()}) } func Chatpage(rw http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) - TplChat.Execute(rw, ChatpageData{"ws://" + req.Host + req.URL.Path + "socket", vars["chatroom"]}) + TplChat.Execute(rw, ChatpageData{"ws://" + req.Host + strings.Replace(req.URL.Path+"/socket", "//", "/", -1), vars["chatroom"]}) } diff --git a/static/chat.css b/static/chat.css new file mode 100644 index 0000000..ed56fca --- /dev/null +++ b/static/chat.css @@ -0,0 +1,97 @@ +* { + font-family: sans-serif; +} + +#chatlog { + display: table; + list-style: none; + margin: 0; + padding: 0 +} + +#chatlog li { + display: table-row; + margin: 0; + padding: 0; +} + +#chatlog li .nick { + display: table-cell; + padding-right: 1ex; + font-weight: bold; + text-align: right; +} + +#chatlog li .msg { + display: table-cell; +} + +#chatlog li.leave, #chatlog li.join, #chatlog li.leave .nick, #chatlog li.join .nick { + color: gray !important; + font-style: italic !important; +} + +h1 { + text-align: center; + font-weight: bold; + font-size: 18pt; + margin: 0; + position: fixed; + top: 0; + left: 0; + right: 0; + border-bottom: 1px solid #28f; + height: 8mm; + background: white; +} + +#buddiescontainer { + position: fixed; + top: 0; + right: 0; + width: 35mm; + margin: 10mm 0 12mm 0; +} + +#buddiescontainer h2 { + font-weight: bold; + font-size: 12pt; +} + +#buddies { + margin: 0; + padding: 0; +} +#buddies li { + margin: 0; + padding: 0; +} + +#chatlog { + margin: 10mm 40mm 12mm 0; +} + +#chatinput { + position: fixed; + bottom: 0; + left: 0; + right: 0; + height: 10mm; + border-top: 1px solid #28f; +} + +#chatinput input { + position: absolute; + top: 0px; + left: 0px; + height: 8mm; + width: calc(100% - 25mm); +} + +#chatinput button { + position: absolute; + top: 0; + right: 0; + width: 20mm; + bottom: 0; +} \ No newline at end of file diff --git a/static/home.css b/static/home.css new file mode 100644 index 0000000..e3dd6ee --- /dev/null +++ b/static/home.css @@ -0,0 +1,38 @@ +* { + font-family: sans-serif; +} + +code { + font-family: monospace; +} + +code strong { + font-family: monospace; + font-weight: bold; +} + +body { + background: hsl(200, 90%, 85%); +} + +section { + background: white; + width: 80%; + min-width: 50mm; + margin: 5mm auto 5mm; + padding: 4mm 0 4mm; + border-radius: 4mm; +} + +section div.content { + padding: 0 4mm; +} + +h1, h2 { + margin: 0 0 2mm; + padding: 2mm 4mm 2mm; + border-bottom: 1px dotted hsl(200, 90%, 85%); + font-weight: normal; + font-size: 18pt; + text-align: center; +} \ No newline at end of file diff --git a/static/style.css b/static/style.css deleted file mode 100644 index ed56fca..0000000 --- a/static/style.css +++ /dev/null @@ -1,97 +0,0 @@ -* { - font-family: sans-serif; -} - -#chatlog { - display: table; - list-style: none; - margin: 0; - padding: 0 -} - -#chatlog li { - display: table-row; - margin: 0; - padding: 0; -} - -#chatlog li .nick { - display: table-cell; - padding-right: 1ex; - font-weight: bold; - text-align: right; -} - -#chatlog li .msg { - display: table-cell; -} - -#chatlog li.leave, #chatlog li.join, #chatlog li.leave .nick, #chatlog li.join .nick { - color: gray !important; - font-style: italic !important; -} - -h1 { - text-align: center; - font-weight: bold; - font-size: 18pt; - margin: 0; - position: fixed; - top: 0; - left: 0; - right: 0; - border-bottom: 1px solid #28f; - height: 8mm; - background: white; -} - -#buddiescontainer { - position: fixed; - top: 0; - right: 0; - width: 35mm; - margin: 10mm 0 12mm 0; -} - -#buddiescontainer h2 { - font-weight: bold; - font-size: 12pt; -} - -#buddies { - margin: 0; - padding: 0; -} -#buddies li { - margin: 0; - padding: 0; -} - -#chatlog { - margin: 10mm 40mm 12mm 0; -} - -#chatinput { - position: fixed; - bottom: 0; - left: 0; - right: 0; - height: 10mm; - border-top: 1px solid #28f; -} - -#chatinput input { - position: absolute; - top: 0px; - left: 0px; - height: 8mm; - width: calc(100% - 25mm); -} - -#chatinput button { - position: absolute; - top: 0; - right: 0; - width: 20mm; - bottom: 0; -} \ No newline at end of file diff --git a/tpls/chat.html b/tpls/chat.html index 35582c7..db34aaa 100644 --- a/tpls/chat.html +++ b/tpls/chat.html @@ -5,7 +5,7 @@ - + diff --git a/tpls/home.html b/tpls/home.html index c559109..fdfa40f 100644 --- a/tpls/home.html +++ b/tpls/home.html @@ -1,9 +1,37 @@ - + simplechat + -Test + +
+

simplechat

+ +
+

simplechat allows you to start a chatroom instantly. No need to register an account or any special programs. A modern webbrowser is enough.

+
+
+ +
+

How to start a new chat

+ +
+

Simple! Just append /chat/roomname to the current URL and you will get a chatroom called roomname. Replace roomname with an arbitrary text.

+

Or use this random chatroom.

+

To invite other people to your new shiny chatroom, just send them the URL.

+
+
+ +
+

Throwaway chatrooms

+ +
+

All created chatrooms are throwaway chatrooms. When the last one leaves the room, it will be gone until someone visits the chat again.

+

Nothing in the chat will be stored permanently on our servers.

+

NOTE: Keep in mind that this service does not use encryption. So please, don't share sensible data that might get you into trouble, there are much better tools for that (XMPP+OTR or GPG, for example).

+
+
- \ No newline at end of file + -- cgit v1.2.3-70-g09d2