Commit 4c48da91 authored by Ronny Bangsund's avatar Ronny Bangsund

Improvements.

-Even better styling (again)
-Username cookie is stored and retrieved (duration: 2 weeks)
-Argument to the index handler renamed to avoid confusion with context parameters
parent 43ec4da2
......@@ -7,7 +7,7 @@
code[class*="language-"],
pre[class*="language-"],
textarea[class*="language-"] {
textarea {
color: white;
text-shadow: 0 -.1em .2em black;
font-family: Consolas, Monaco, 'Andale Mono', monospace;
......@@ -27,6 +27,9 @@ textarea[class*="language-"] {
hyphens: none;
}
textarea {
text-shadow: none;
}
@media print {
code[class*="language-"],
pre[class*="language-"] {
......@@ -35,14 +38,14 @@ textarea[class*="language-"] {
}
pre[class*="language-"],
textarea[class*="language-"],
textarea,
:not(pre) > code[class*="language-"] {
background: hsl(30,20%,25%);
}
/* Code blocks */
pre[class*="language-"],
textarea[class*="language-"] {
textarea {
padding: 1em;
margin: .5em 0;
overflow: auto;
......
......@@ -27,10 +27,10 @@
{{end}}
</select>
<label for="expiry" style="left:2px;top:2px;position:relative;float:left;">Expiry:</label>
<textarea class="language-" name="content" style="left:0;top:28px;width:100%;height:400px;margin:1%;color:black;background-color:transparent;border:0px"></textarea>
<textarea name="content" style="left:0;top:28px;width:100%;height:400px;margin:1%;color:black;background-color:transparent;"></textarea>
<input type="submit" value="Post scrap" />
<label for="username" style="left:20px; position:relative; top:2px;">Username:</label>
<input type="text" name="username" value="anonymous" style="position:relative; left:19px; top:1px; width:192px;" />
<input type="text" name="username" value="{{.Username}}" style="position:relative; left:19px; top:1px; width:192px;" />
</form>
</div>
......
......@@ -14,6 +14,7 @@ type IndexPage struct {
View bool
Language string
Content string
Username string
Links []ScrapLink
}
......@@ -37,16 +38,21 @@ func endWeb() {
web.Close()
}
func get_index(ctx *web.Context, p string) {
func get_index(ctx *web.Context, arg string) {
ctx.SetHeader("Content-type", "text/html", true)
user := "anonymous"
cookie, err := ctx.Request.Cookie("usercookie")
if err == nil {
user = cookie.Value
}
buildLinks()
title := cfg.Main.Sitename
name := cfg.Main.Sitename
view := false
var s Scrap
var lang string
if p != "" {
s = loadScrap(sane(p))
if arg != "" {
s = loadScrap(sane(arg))
info("Links: %d (%d)", len(links), len(scraps))
if !s.hasExpired() {
view = true
......@@ -60,18 +66,23 @@ func get_index(ctx *web.Context, p string) {
View: view,
Language: lang,
Content: s.Content,
Username: user,
Links: links,
})
}
func post_scrap(ctx *web.Context) {
p := ctx.Params
user := sane(p["username"])
if user != "" {
ctx.SetCookie(web.NewCookie("usercookie", user, 1209600)) // 2-week cookie
}
lang := sane(p["language"])
if !validLanguage(lang) {
info("Invalid language '%s' from %s.", lang, ctx.Request.RemoteAddr)
return
}
user := sane(p["username"])
content := p["content"]
expiry := sane(p["expiry"])
when := int64(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment