all repos — honk @ 762b75764b454c958e79b083a5a2a2911e7cc03b

my fork of honk

optional skinny column mode
Ted Unangst tedu@tedunangst.com
Thu, 27 Jun 2019 22:36:55 -0400
commit

762b75764b454c958e79b083a5a2a2911e7cc03b

parent

9fd970ce7e1b1de5018279892bb6bbb3e9260a25

4 files changed, 36 insertions(+), 10 deletions(-)

jump to
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

-- next ++ Support for some user selectable styling. Currently, skinny column mode. + + webp image transcoding. -- 0.7.3
M honk.gohonk.go

@@ -42,12 +42,13 @@ "humungus.tedunangst.com/r/webs/templates"

) type WhatAbout struct { - ID int64 - Name string - Display string - About string - Key string - URL string + ID int64 + Name string + Display string + About string + Key string + URL string + SkinnyCSS bool } type Honk struct {

@@ -97,13 +98,26 @@ var serverMsg = "Things happen."

var readviews *templates.Template +func getuserstyle(u *login.UserInfo) template.CSS { + if u == nil { + return "" + } + user, _ := butwhatabout(u.Username) + if user.SkinnyCSS { + return "main { max-width: 700px; }" + } + return "" +} + func getInfo(r *http.Request) map[string]interface{} { + u := login.GetUserInfo(r) templinfo := make(map[string]interface{}) templinfo["StyleParam"] = getstyleparam("views/style.css") templinfo["LocalStyleParam"] = getstyleparam("views/local.css") + templinfo["UserStyle"] = getuserstyle(u) templinfo["ServerName"] = serverName templinfo["IconName"] = iconName - templinfo["UserInfo"] = login.GetUserInfo(r) + templinfo["UserInfo"] = u return templinfo }

@@ -238,6 +252,7 @@ var user WhatAbout

var options string err := row.Scan(&user.ID, &user.Name, &user.Display, &user.About, &user.Key, &options) user.URL = fmt.Sprintf("https://%s/u/%s", serverName, user.Name) + user.SkinnyCSS = strings.Contains(options, " skinny ") return &user, err }

@@ -617,7 +632,11 @@ func saveuser(w http.ResponseWriter, r *http.Request) {

whatabout := r.FormValue("whatabout") u := login.GetUserInfo(r) db := opendatabase() - _, err := db.Exec("update users set about = ? where username = ?", whatabout, u.Username) + options := "" + if r.FormValue("skinny") == "skinny" { + options += " skinny " + } + _, err := db.Exec("update users set about = ?, options = ? where username = ?", whatabout, options, u.Username) if err != nil { log.Printf("error bouting what: %s", err) }

@@ -1248,7 +1267,7 @@ user, _ := butwhatabout(u.Username)

templinfo := getInfo(r) templinfo["UserCSRF"] = login.GetCSRF("saveuser", r) templinfo["LogoutCSRF"] = login.GetCSRF("logout", r) - templinfo["WhatAbout"] = user.About + templinfo["User"] = user err := readviews.Execute(w, "account.html", templinfo) if err != nil { log.Print(err)
M views/account.htmlviews/account.html

@@ -7,7 +7,9 @@ <div>

<form id="aboutform" action="/saveuser" method="POST"> <p>about <input type="hidden" name="CSRF" value="{{ .UserCSRF }}"> -<p><textarea name="whatabout">{{ .WhatAbout }}</textarea> +<p><textarea name="whatabout">{{ .User.About }}</textarea> +<p><span><label for="skinny">skinny layout:</label> +<input tabindex=1 type="checkbox" id="skinny" name="skinny" value="skinny" {{ if .User.SkinnyCSS }}checked{{ end }}><span></span></span> <p><input type="submit" value="update"> </form> </div>
M views/header.htmlviews/header.html

@@ -6,6 +6,9 @@ <link href="/style.css{{ .StyleParam }}" rel="stylesheet">

{{ if .LocalStyleParam }} <link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet"> {{ end }} +<style> +{{ .UserStyle }} +</style> <link href="/icon.png" rel="icon"> <meta name="viewport" content="width=device-width"> </head>