optional skinny column mode
This commit is contained in:
parent
5e59b3ecef
commit
67d57f56d8
|
@ -2,6 +2,8 @@ changelog
|
||||||
|
|
||||||
-- next
|
-- next
|
||||||
|
|
||||||
|
+ Support for some user selectable styling. Currently, skinny column mode.
|
||||||
|
|
||||||
+ webp image transcoding.
|
+ webp image transcoding.
|
||||||
|
|
||||||
-- 0.7.3
|
-- 0.7.3
|
||||||
|
|
37
honk.go
37
honk.go
|
@ -42,12 +42,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type WhatAbout struct {
|
type WhatAbout struct {
|
||||||
ID int64
|
ID int64
|
||||||
Name string
|
Name string
|
||||||
Display string
|
Display string
|
||||||
About string
|
About string
|
||||||
Key string
|
Key string
|
||||||
URL string
|
URL string
|
||||||
|
SkinnyCSS bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Honk struct {
|
type Honk struct {
|
||||||
|
@ -97,13 +98,26 @@ var serverMsg = "Things happen."
|
||||||
|
|
||||||
var readviews *templates.Template
|
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{} {
|
func getInfo(r *http.Request) map[string]interface{} {
|
||||||
|
u := login.GetUserInfo(r)
|
||||||
templinfo := make(map[string]interface{})
|
templinfo := make(map[string]interface{})
|
||||||
templinfo["StyleParam"] = getstyleparam("views/style.css")
|
templinfo["StyleParam"] = getstyleparam("views/style.css")
|
||||||
templinfo["LocalStyleParam"] = getstyleparam("views/local.css")
|
templinfo["LocalStyleParam"] = getstyleparam("views/local.css")
|
||||||
|
templinfo["UserStyle"] = getuserstyle(u)
|
||||||
templinfo["ServerName"] = serverName
|
templinfo["ServerName"] = serverName
|
||||||
templinfo["IconName"] = iconName
|
templinfo["IconName"] = iconName
|
||||||
templinfo["UserInfo"] = login.GetUserInfo(r)
|
templinfo["UserInfo"] = u
|
||||||
return templinfo
|
return templinfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,6 +252,7 @@ func butwhatabout(name string) (*WhatAbout, error) {
|
||||||
var options string
|
var options string
|
||||||
err := row.Scan(&user.ID, &user.Name, &user.Display, &user.About, &user.Key, &options)
|
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.URL = fmt.Sprintf("https://%s/u/%s", serverName, user.Name)
|
||||||
|
user.SkinnyCSS = strings.Contains(options, " skinny ")
|
||||||
return &user, err
|
return &user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,7 +632,11 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
|
||||||
whatabout := r.FormValue("whatabout")
|
whatabout := r.FormValue("whatabout")
|
||||||
u := login.GetUserInfo(r)
|
u := login.GetUserInfo(r)
|
||||||
db := opendatabase()
|
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 {
|
if err != nil {
|
||||||
log.Printf("error bouting what: %s", err)
|
log.Printf("error bouting what: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -1248,7 +1267,7 @@ func accountpage(w http.ResponseWriter, r *http.Request) {
|
||||||
templinfo := getInfo(r)
|
templinfo := getInfo(r)
|
||||||
templinfo["UserCSRF"] = login.GetCSRF("saveuser", r)
|
templinfo["UserCSRF"] = login.GetCSRF("saveuser", r)
|
||||||
templinfo["LogoutCSRF"] = login.GetCSRF("logout", r)
|
templinfo["LogoutCSRF"] = login.GetCSRF("logout", r)
|
||||||
templinfo["WhatAbout"] = user.About
|
templinfo["User"] = user
|
||||||
err := readviews.Execute(w, "account.html", templinfo)
|
err := readviews.Execute(w, "account.html", templinfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
<form id="aboutform" action="/saveuser" method="POST">
|
<form id="aboutform" action="/saveuser" method="POST">
|
||||||
<p>about
|
<p>about
|
||||||
<input type="hidden" name="CSRF" value="{{ .UserCSRF }}">
|
<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">
|
<p><input type="submit" value="update">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
{{ if .LocalStyleParam }}
|
{{ if .LocalStyleParam }}
|
||||||
<link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet">
|
<link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<style>
|
||||||
|
{{ .UserStyle }}
|
||||||
|
</style>
|
||||||
<link href="/icon.png" rel="icon">
|
<link href="/icon.png" rel="icon">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in New Issue