diff --git a/Makefile b/Makefile index a7e0a0c..1b88d82 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: mlmym -mlmym: +mlmym: VERSION go build -v -o mlmym dev: diff --git a/README.md b/README.md index ee99f9e..c2bde67 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,23 @@ a familiar desktop experience for [lemmy](https://join-lemmy.org). ![screenshot](https://raw.githubusercontent.com/rystaf/mlmym/main/screenshot1.png?raw=true) -### deployment +## deployment ```bash docker run -it -p "8080:8080" ghcr.io/rystaf/mlmym:latest ``` -### config +## config Set the environment variable `LEMMY_DOMAIN` to run in single instance mode ```bash docker run -it -e LEMMY_DOMAIN='lemmydomain.com' -p "8080:8080" ghcr.io/rystaf/mlmym:latest ``` +#### default user settings +| environment variable | default | +| -------------------- | ------- | +| DARK | false | +| HIDE_THUMBNAILS | false | +| LISTING | All | +| SORT | Hot | +| COMMENT_SORT | Hot | + diff --git a/main.go b/main.go index 4c49046..95e0f3d 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,7 @@ func init() { )) templates = make(map[string]*template.Template) if !*watch { - for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html", "xhr.html"} { + for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html", "xhr.html", "create_comment.html"} { t := template.New(name).Funcs(funcMap) glob, err := t.ParseGlob("templates/*") if err != nil { diff --git a/public/style.css b/public/style.css index 7b8a084..7522f61 100644 --- a/public/style.css +++ b/public/style.css @@ -1110,7 +1110,7 @@ form.create input[type=file], form.create select { } .preferences label{ display: inline-block; - width: 130px; + width: 150px; margin-right: 5px; text-align: right; diff --git a/routes.go b/routes.go index 02e38ed..d72d653 100644 --- a/routes.go +++ b/routes.go @@ -152,7 +152,7 @@ var funcMap = template.FuncMap{ return body } text := html2text.HTML2TextWithOptions(buf.String(), html2text.WithLinksInnerText()) - re := regexp.MustCompile(`\`) + re := regexp.MustCompile(`\<(https?:\/\/|mailto)(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)\>`) return re.ReplaceAllString(text, "") }, "contains": strings.Contains, @@ -208,6 +208,14 @@ func RegReplace(input string, match string, replace string) string { return re.ReplaceAllString(input, replace) } +func getenv(key, fallback string) string { + value := os.Getenv(key) + if len(value) == 0 { + return fallback + } + return value +} + func Initialize(Host string, r *http.Request) (State, error) { state := State{ Host: Host, @@ -252,18 +260,27 @@ func Initialize(Host string, r *http.Request) (State, error) { state.Listing = getCookie(r, "DefaultListingType") state.Sort = getCookie(r, "DefaultSortType") state.CommentSort = getCookie(r, "DefaultCommentSortType") - state.Dark = getCookie(r, "Dark") != "" + if dark := getCookie(r, "Dark"); dark != "" { + state.Dark = dark != "0" + } else { + state.Dark = os.Getenv("DARK") != "" + } state.ShowNSFW = getCookie(r, "ShowNSFW") != "" state.HideInstanceNames = getCookie(r, "HideInstanceNames") != "" + if hide := getCookie(r, "HideThumbnails"); hide != "" { + state.HideThumbnails = hide != "0" + } else { + state.HideThumbnails = os.Getenv("HIDE_THUMBNAILS") != "" + } state.ParseQuery(r.URL.RawQuery) if state.Sort == "" { - state.Sort = "Hot" + state.Sort = getenv("SORT", "Hot") } if state.CommentSort == "" { - state.CommentSort = "Hot" + state.CommentSort = getenv("COMMENT_SORT", "Hot") } if state.Listing == "" || state.Session == nil && state.Listing == "Subscribed" { - state.Listing = "All" + state.Listing = getenv("LISTING", "All") } return state, nil } @@ -687,6 +704,7 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { Render(w, "index.html", state) return } + state.GetSite() switch r.Method { case "POST": for _, name := range []string{"DefaultSortType", "DefaultListingType", "DefaultCommentSortType"} { @@ -697,8 +715,7 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { setCookie(w, "", "Dark", "1") state.Dark = true } else { - deleteCookie(w, state.Host, "Dark") - deleteCookie(w, "", "Dark") + setCookie(w, "", "Dark", "0") state.Dark = false } if r.FormValue("shownsfw") != "" { @@ -716,6 +733,13 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { deleteCookie(w, "", "HideInstanceNames") state.HideInstanceNames = false } + if r.FormValue("hideThumbnails") != "" { + setCookie(w, "", "HideThumbnails", "1") + state.HideInstanceNames = true + } else { + setCookie(w, "", "HideThumbnails", "0") + state.HideInstanceNames = false + } state.Listing = r.FormValue("DefaultListingType") state.Sort = r.FormValue("DefaultSortType") state.CommentSort = r.FormValue("DefaultCommentSortType") diff --git a/state.go b/state.go index b45dfc0..1e2085a 100644 --- a/state.go +++ b/state.go @@ -104,6 +104,7 @@ type State struct { Dark bool ShowNSFW bool HideInstanceNames bool + HideThumbnails bool } func (s State) Unknown() string { diff --git a/templates/comment.html b/templates/comment.html index 631132c..c33d77a 100644 --- a/templates/comment.html +++ b/templates/comment.html @@ -52,6 +52,7 @@ {{ end }}