summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-03-27 23:48:11 +0100
committerKevin Chabowski <kevin@kch42.de>2014-03-27 23:51:08 +0100
commitfeb228c1fc35aae543d369012994eac7a1dca90f (patch)
treed2a9b7cf449b3e1e8d48e2bc36b0b383ee5f658a
parent5c45b0e3e5fbe479155ad403b4936d2485a028bd (diff)
downloadsimplechat-feb228c1fc35aae543d369012994eac7a1dca90f.tar.gz
simplechat-feb228c1fc35aae543d369012994eac7a1dca90f.tar.bz2
simplechat-feb228c1fc35aae543d369012994eac7a1dca90f.zip
Homepage done
-rw-r--r--main.go3
-rw-r--r--pages.go22
-rw-r--r--static/chat.css (renamed from static/style.css)0
-rw-r--r--static/home.css38
-rw-r--r--tpls/chat.html2
-rw-r--r--tpls/home.html34
6 files changed, 92 insertions, 7 deletions
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/style.css b/static/chat.css
index ed56fca..ed56fca 100644
--- a/static/style.css
+++ b/static/chat.css
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/tpls/chat.html b/tpls/chat.html
index 35582c7..db34aaa 100644
--- a/tpls/chat.html
+++ b/tpls/chat.html
@@ -5,7 +5,7 @@
<script type="text/javascript" src="/static/jquery.min.js"></script>
<script type="text/javascript" src="/static/chat.js"></script>
<script type="text/javascript">$("document").ready(function(){RunChat("{{.Websock}}");});</script>
- <link rel="stylesheet" type="text/css" href="/static/style.css" />
+ <link rel="stylesheet" type="text/css" href="/static/chat.css" />
</head>
<body>
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 @@
<!DOCTYPE html>
<html>
<head>
- <title></title>
+ <title>simplechat</title>
+ <link rel="stylesheet" type="text/css" href="/static/home.css">
</head>
<body>
-Test
+
+ <section>
+ <h1>simplechat</h1>
+
+ <div class="content">
+ <p>simplechat allows you to start a chatroom instantly. No need to register an account or any special programs. A modern webbrowser is enough.</p>
+ </div>
+ </section>
+
+ <section>
+ <h2>How to start a new chat</h2>
+
+ <div class="content">
+ <p>Simple! Just append <code>/chat/<strong>roomname</strong></code> to the current URL and you will get a chatroom called <code>roomname</code>. Replace <code>roomname</code> with an arbitrary text.</p>
+ <p>Or use <a href="/chat/{{.RandomChat}}">this random chatroom</a>.</p>
+ <p>To invite other people to your new shiny chatroom, just send them the URL.</p>
+ </div>
+ </section>
+
+ <section>
+ <h2>Throwaway chatrooms</h2>
+
+ <div class="content">
+ <p>All created chatrooms are throwaway chatrooms. When the last one leaves the room, it will be gone until someone visits the chat again.</p>
+ <p>Nothing in the chat will be stored permanently on our servers.</p>
+ <p><strong>NOTE:</strong> Keep in mind that this service does <em>not</em> 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).</p>
+ </div>
+ </section>
</body>
-</html> \ No newline at end of file
+</html>