Commit 050fc7ff authored by Ronny Bangsund's avatar Ronny Bangsund

Favourite language option.

-The most recently used language is stored in a cookie and set as default for the next two weeks
parent d41fe1c4
......@@ -21,8 +21,9 @@
</select>
<select name="language" style="position:relative;left:10px;top:0;">
{{with .}}
{{$x := .Fave}}
{{range $k,$v := .Languages}}
<option value="{{$k}}">{{$v}}</option>
<option {{if eq $k $x}}selected="selected" {{end}}value="{{$k}}">{{$v}}</option>
{{end}}
{{end}}
</select>
......
......@@ -13,6 +13,7 @@ type IndexPage struct {
Languages map[string]string
View bool
Language string
Fave string
Content string
Username string
Links []ScrapLink
......@@ -45,6 +46,11 @@ func get_index(ctx *web.Context, arg string) {
if err == nil {
user = cookie.Value
}
fave := "text"
cookie, err = ctx.Request.Cookie("langcookie")
if err == nil {
fave = cookie.Value
}
buildLinks()
title := cfg.Main.Sitename
name := cfg.Main.Sitename
......@@ -65,6 +71,7 @@ func get_index(ctx *web.Context, arg string) {
Languages: languages,
View: view,
Language: lang,
Fave: fave,
Content: s.Content,
Username: user,
Links: links,
......@@ -81,8 +88,10 @@ func post_scrap(ctx *web.Context) {
lang := sane(p["language"])
if !validLanguage(lang) {
info("Invalid language '%s' from %s.", lang, ctx.Request.RemoteAddr)
ctx.Redirect(303, "/")
return
}
ctx.SetCookie(web.NewCookie("langcookie", lang, 1209600))
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