From 2d8a3d23156883ff2e0c50d26bbb6d5a1a321e2f Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Sat, 15 Jul 2023 20:59:32 -0400 Subject: [PATCH 01/32] localize community and user links, regex cleanup --- Makefile | 2 +- main.go | 35 ++++++++++++++++++++++++ routes.go | 59 ++++++++++++++++++++++++++++------------ templates/community.html | 4 +-- 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index ca918f2..0ac9db1 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ reload: serve: #python -m http.server --directory ./public 8081 &>/dev/null - watchexec -e go -r "go run . --addr 0.0.0.0:8008 -w" + DEBUG=true watchexec -e go -r "go run . --addr 0.0.0.0:8008 -w" style: npm run watchcss > /dev/null 2>&1 diff --git a/main.go b/main.go index ca577c2..b00f6cc 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net" "net/http" + "os" "github.com/julienschmidt/httprouter" "github.com/yuin/goldmark" @@ -64,6 +65,40 @@ func init() { templates[name] = glob } } + if os.Getenv("DEBUG") != "" { + test() + } +} +func test() { + links := [][]string{ + []string{"https://lemmy.local/u/dude", "/lemmy.local/u/dude", "/u/dude"}, + []string{"https://lemmy.local/u/dude@lemmy.local", "/lemmy.local/u/dude", "/u/dude"}, + []string{"/u/dude", "/lemmy.local/u/dude", "/u/dude"}, + []string{"https://lemmy.world/c/dude", "/lemmy.local/c/dude@lemmy.world", "/c/dude@lemmy.world"}, + []string{"https://lemmy.world/u/dude", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, + []string{"https://lemmy.world/u/dude@lemmy.world", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, + []string{"https://lemmy.world/post/123", "/lemmy.world/post/123", "https://lemmy.world/post/123"}, + []string{"/post/123", "/lemmy.local/post/123", "/post/123"}, + []string{"/comment/123", "/lemmy.local/comment/123", "/comment/123"}, + []string{"https://lemmy.local/comment/123", "/lemmy.local/comment/123", "/comment/123"}, + } + for _, url := range links { + output := LemmyLinkRewrite(`href="`+url[0]+`"`, "lemmy.local", "") + success := (output == (`href="` + url[1] + `"`)) + if !success { + fmt.Println("\n!!!! Link rewrite failure !!!!") + fmt.Println(url) + fmt.Println(output) + fmt.Println("") + } + output = LemmyLinkRewrite(`href="`+url[0]+`"`, ".", "lemmy.local") + success = (output == (`href="` + url[2] + `"`)) + if !success { + fmt.Println(success, url) + fmt.Println(output) + fmt.Println("") + } + } } func middleware(n httprouter.Handle) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { diff --git a/routes.go b/routes.go index 17c8355..a933b77 100644 --- a/routes.go +++ b/routes.go @@ -32,12 +32,12 @@ var funcMap = template.FuncMap{ } return host }, - "proxy": func(s string) string { + "localize": func(s string) string { u, err := url.Parse(s) if err != nil { return s } - return "/" + u.Host + u.Path + return "." + u.Path + "@" + u.Host }, "printer": func(n any) string { p := message.NewPrinter(language.English) @@ -137,22 +137,11 @@ var funcMap = template.FuncMap{ fmt.Println(err) return template.HTML(body) } - converted := buf.String() - converted = strings.Replace(converted, `!$1@$2 `) - if os.Getenv("LEMMY_DOMAIN") == "" { - re = regexp.MustCompile(`href="\/(c\/[a-zA-Z0-9\-]+|(post|comment)\/\d+)`) - converted = re.ReplaceAllString(converted, `href="https://`+host+`/$1`) - re := regexp.MustCompile(`href="https:\/\/([a-zA-Z0-9\.\-]+\/(c\/[a-zA-Z0-9]+|(post|comment)\/\d+))`) - converted = re.ReplaceAllString(converted, `href="/$1`) - } else { - re := regexp.MustCompile(`href="https:\/\/` + os.Getenv("LEMMY_DOMAIN") + `\/(c\/[a-zA-Z0-9]+|(post|comment)\/\d+)`) - converted = re.ReplaceAllString(converted, `href="/$1`) - } - re = regexp.MustCompile(`::: spoiler (.*?)\n([\S\s]*?):::`) - converted = re.ReplaceAllString(converted, "
$1$2
") - return template.HTML(converted) + body = buf.String() + body = strings.Replace(body, `$1$2") + return template.HTML(body) }, "rmmarkdown": func(body string) string { var buf bytes.Buffer @@ -173,6 +162,40 @@ var funcMap = template.FuncMap{ }, } +func LemmyLinkRewrite(input string, host string, lemmy_domain string) (body string) { + body = input + // community bangs + body = RegReplace(body, `!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)[ $]?`, `!$1@$2 `) + // localize community and user links + body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+)\/((c|u)\/.*?)"`, `href="/$2@$1"`) + // remove extra instance tag + body = RegReplace(body, `href="\/((c|u)\/.*@.*?)@(.*?)"`, `href="/$1"`) + if lemmy_domain == "" { + // add domain to relative links + body = RegReplace(body, `href="\/(c\/[a-zA-Z0-9\-]+"|(post|comment)\/\d+"|(c|u)\/(.*?)")`, `href="/`+host+`/$1`) + // convert links to relative + body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+\/(c\/[a-zA-Z0-9]+"|(post|comment)\/\d+"|u\/(.*?)"))`, `href="/$1`) + } else { + // convert local links to relative + body = RegReplace(body, `href="https:\/\/`+lemmy_domain+`\/(c\/[a-zA-Z0-9]+"|(post|comment)\/\d+"|u\/(.*?)")`, `href="/$1`) + body = RegReplace(body, `href="(.*)@`+lemmy_domain+`"`, `href="$1"`) + } + // remove redundant instance tag + re := regexp.MustCompile(`href="\/([a-zA-Z0-9\.\-]+)\/(c|u)\/(.*?)@(.*?)"`) + matches := re.FindAllStringSubmatch(body, -1) + for _, match := range matches { + if match[1] == match[4] { + body = strings.Replace(body, match[0], `href="/`+strings.Join(match[1:4], "/")+`"`, -1) + } + } + return body +} + +func RegReplace(input string, match string, replace string) string { + re := regexp.MustCompile(match) + return re.ReplaceAllString(input, replace) +} + func Initialize(Host string, r *http.Request) (State, error) { state := State{ Host: Host, diff --git a/templates/community.html b/templates/community.html index f1af3c6..42d3f26 100644 --- a/templates/community.html +++ b/templates/community.html @@ -3,11 +3,11 @@ - c/{{fullcname .Community}}: {{.Community.Title}} + c/{{fullcname .Community}}: {{.Community.Title}}
{{ if .Community.Description.IsValid }}
- {{markdown "poop" .Community.Description.String}} + {{markdown "" .Community.Description.String}}
{{ end }}
From 23d08a730cd59a9c039fb73c0440710c8990489d Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Sat, 15 Jul 2023 22:07:19 -0400 Subject: [PATCH 02/32] try remote instance link --- state.go | 34 ++++++++++++++++++++++++++++++++++ templates/frontpage.html | 7 ++++++- templates/main.html | 7 ++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/state.go b/state.go index b271855..ed3ad28 100644 --- a/state.go +++ b/state.go @@ -11,6 +11,8 @@ import ( "mime/multipart" "net/http" "net/url" + "os" + "regexp" "sort" "strconv" "strings" @@ -100,6 +102,37 @@ type State struct { HideInstanceNames bool } +func (s State) Unknown() string { + fmt.Println(fmt.Sprintf("%v", s.Error)) + re := regexp.MustCompile(`(.*?)@(.*?)@`) + if strings.Contains(fmt.Sprintf("%v", s.Error), "couldnt_find_community") { + matches := re.FindAllStringSubmatch(s.CommunityName+"@", -1) + if len(matches) < 1 || len(matches[0]) < 3 { + return "" + } + if matches[0][2] != s.Host { + remote := "/" + matches[0][2] + "/c/" + matches[0][1] + if os.Getenv("LEMMY_DOMAIN") != "" { + remote = "https:/" + remote + } + return remote + } + } + if strings.Contains(fmt.Sprintf("%v", s.Error), "couldnt_find_that_username_or_email") { + matches := re.FindAllStringSubmatch(s.UserName+"@", -1) + if len(matches) < 1 || len(matches[0]) < 3 { + return "" + } + if matches[0][2] != s.Host { + remote := "/" + matches[0][2] + "/u/" + matches[0][1] + if os.Getenv("LEMMY_DOMAIN") != "" { + remote = "https:/" + remote + } + return remote + } + } + return "" +} func (p State) SortBy(v string) string { var q string if p.Query != "" || p.SearchType == "Communities" { @@ -411,6 +444,7 @@ func (state *State) GetUser(username string) { }) if err != nil { fmt.Println(err) + state.Error = err state.Status = http.StatusInternalServerError return } diff --git a/templates/frontpage.html b/templates/frontpage.html index b812252..63637d1 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -34,7 +34,12 @@ {{ end}} {{ if .Error }} -
{{.Error}}
+
+ {{.Error}}. + {{ if .Unknown }} + try remote instance: {{ .Unknown }} + {{ end }} +
{{ end }} {{ range .Posts }} diff --git a/templates/main.html b/templates/main.html index ed08e98..e2d6390 100644 --- a/templates/main.html +++ b/templates/main.html @@ -56,7 +56,12 @@ {{ end}} {{ if .Error }} -
{{.Error}}
+
+ {{.Error}}. + {{ if .Unknown }} + try remote instance: {{ .Unknown }} + {{ end }} +
{{ end }} {{ range .Communities }} From 9782144dcb041908113a306e183205de3eb525f5 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Sat, 15 Jul 2023 22:41:39 -0400 Subject: [PATCH 03/32] rewrite fix --- main.go | 2 ++ routes.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b00f6cc..c50efbe 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,8 @@ func test() { []string{"https://lemmy.local/u/dude", "/lemmy.local/u/dude", "/u/dude"}, []string{"https://lemmy.local/u/dude@lemmy.local", "/lemmy.local/u/dude", "/u/dude"}, []string{"/u/dude", "/lemmy.local/u/dude", "/u/dude"}, + []string{"/u/dude@lemmy.world", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, + []string{"/u/dude@lemmy.local", "/lemmy.local/u/dude", "/u/dude"}, []string{"https://lemmy.world/c/dude", "/lemmy.local/c/dude@lemmy.world", "/c/dude@lemmy.world"}, []string{"https://lemmy.world/u/dude", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, []string{"https://lemmy.world/u/dude@lemmy.world", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, diff --git a/routes.go b/routes.go index a933b77..8ff74d1 100644 --- a/routes.go +++ b/routes.go @@ -165,11 +165,11 @@ var funcMap = template.FuncMap{ func LemmyLinkRewrite(input string, host string, lemmy_domain string) (body string) { body = input // community bangs - body = RegReplace(body, `!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)[ $]?`, `!$1@$2 `) + body = RegReplace(body, `!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)([ \n\r]+|<\/p>)`, `!$1@$2 `) // localize community and user links body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+)\/((c|u)\/.*?)"`, `href="/$2@$1"`) // remove extra instance tag - body = RegReplace(body, `href="\/((c|u)\/.*@.*?)@(.*?)"`, `href="/$1"`) + body = RegReplace(body, `href="(https:\/)?(\/[a-zA-Z0-9\.\-]+)?\/((c|u)\/[a-zA-Z0-9]+@[a-zA-Z0-9\.\-]+)@([a-zA-Z0-9\.\-]+)"`, `href="/$3"`) if lemmy_domain == "" { // add domain to relative links body = RegReplace(body, `href="\/(c\/[a-zA-Z0-9\-]+"|(post|comment)\/\d+"|(c|u)\/(.*?)")`, `href="/`+host+`/$1`) From 0f4242e61e645fbcb5d62625c32c6d7d12e38b9e Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Sun, 16 Jul 2023 09:00:49 -0400 Subject: [PATCH 04/32] localize post and comment links --- main.go | 5 +-- routes.go | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- state.go | 28 ++++++++--------- 3 files changed, 103 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index c50efbe..a7aee4f 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func test() { []string{"https://lemmy.world/c/dude", "/lemmy.local/c/dude@lemmy.world", "/c/dude@lemmy.world"}, []string{"https://lemmy.world/u/dude", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, []string{"https://lemmy.world/u/dude@lemmy.world", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, - []string{"https://lemmy.world/post/123", "/lemmy.world/post/123", "https://lemmy.world/post/123"}, + []string{"https://lemmy.world/post/123", "/lemmy.local/post/123@lemmy.world", "/post/123@lemmy.world"}, []string{"/post/123", "/lemmy.local/post/123", "/post/123"}, []string{"/comment/123", "/lemmy.local/comment/123", "/comment/123"}, []string{"https://lemmy.local/comment/123", "/lemmy.local/comment/123", "/comment/123"}, @@ -88,7 +88,7 @@ func test() { output := LemmyLinkRewrite(`href="`+url[0]+`"`, "lemmy.local", "") success := (output == (`href="` + url[1] + `"`)) if !success { - fmt.Println("\n!!!! Link rewrite failure !!!!") + fmt.Println("\n!!!! multi instance link rewrite failure !!!!") fmt.Println(url) fmt.Println(output) fmt.Println("") @@ -96,6 +96,7 @@ func test() { output = LemmyLinkRewrite(`href="`+url[0]+`"`, ".", "lemmy.local") success = (output == (`href="` + url[2] + `"`)) if !success { + fmt.Println("\n!!!! single instance link rewrite failure !!!!") fmt.Println(success, url) fmt.Println(output) fmt.Println("") diff --git a/routes.go b/routes.go index 8ff74d1..7f690f1 100644 --- a/routes.go +++ b/routes.go @@ -167,21 +167,21 @@ func LemmyLinkRewrite(input string, host string, lemmy_domain string) (body stri // community bangs body = RegReplace(body, `!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)([ \n\r]+|<\/p>)`, `!$1@$2 `) // localize community and user links - body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+)\/((c|u)\/.*?)"`, `href="/$2@$1"`) + body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+)\/((c|u|comment|post)\/.*?)"`, `href="/$2@$1"`) // remove extra instance tag body = RegReplace(body, `href="(https:\/)?(\/[a-zA-Z0-9\.\-]+)?\/((c|u)\/[a-zA-Z0-9]+@[a-zA-Z0-9\.\-]+)@([a-zA-Z0-9\.\-]+)"`, `href="/$3"`) if lemmy_domain == "" { // add domain to relative links - body = RegReplace(body, `href="\/(c\/[a-zA-Z0-9\-]+"|(post|comment)\/\d+"|(c|u)\/(.*?)")`, `href="/`+host+`/$1`) + body = RegReplace(body, `href="\/((c|u|post|comment)\/(.*?)")`, `href="/`+host+`/$1`) // convert links to relative - body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+\/(c\/[a-zA-Z0-9]+"|(post|comment)\/\d+"|u\/(.*?)"))`, `href="/$1`) + body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+\/((c|u|post|comment)\/[a-zA-Z0-9]+"))`, `href="/$1`) } else { // convert local links to relative - body = RegReplace(body, `href="https:\/\/`+lemmy_domain+`\/(c\/[a-zA-Z0-9]+"|(post|comment)\/\d+"|u\/(.*?)")`, `href="/$1`) + body = RegReplace(body, `href="https:\/\/`+lemmy_domain+`\/(c\/[a-zA-Z0-9]+"|(c|u|post|comment)\/(.*?)")`, `href="/$1`) body = RegReplace(body, `href="(.*)@`+lemmy_domain+`"`, `href="$1"`) } // remove redundant instance tag - re := regexp.MustCompile(`href="\/([a-zA-Z0-9\.\-]+)\/(c|u)\/(.*?)@(.*?)"`) + re := regexp.MustCompile(`href="\/([a-zA-Z0-9\.\-]+)\/(c|u|post|comment)\/(.*?)@(.*?)"`) matches := re.FindAllStringSubmatch(body, -1) for _, match := range matches { if match[1] == match[4] { @@ -416,12 +416,67 @@ func GetFrontpage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) } } +func ResolveId(r *http.Request, class string, id string, host string) string { + remoteAddr := r.RemoteAddr + if r.Header.Get("CF-Connecting-IP") != "" { + remoteAddr = r.Header.Get("CF-Connecting-IP") + } + client := http.Client{Transport: NewAddHeaderTransport(remoteAddr)} + c, err := lemmy.NewWithClient("https://"+host, &client) + if err != nil { + return "" + } + idn, _ := strconv.Atoi(id) + if class == "post" { + resp, err := c.Post(context.Background(), types.GetPost{ + ID: types.NewOptional(idn), + }) + if err != nil { + return "" + } + return resp.PostView.Post.ApID + } + resp, err := c.Comment(context.Background(), types.GetComment{ + ID: idn, + }) + if err != nil { + return "" + } + return resp.CommentView.Comment.ApID +} + func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { state, err := Initialize(ps.ByName("host"), r) if err != nil { Render(w, "index.html", state) return } + if path := strings.Split(ps.ByName("postid"), "@"); len(path) > 1 { + apid := ResolveId(r, "post", path[0], path[1]) + if apid != "" { + resp, err := state.Client.ResolveObject(context.Background(), types.ResolveObject{ + Q: apid, + }) + if err != nil { + dest := apid + if os.Getenv("LEMMY_DOMAIN") == "" { + dest = RegReplace(dest, `https:\/\/([a-zA-Z0-9\.\-]+\/post\/\d+)`, `/$1`) + } + http.Redirect(w, r, dest, 302) + return + } + post, _ := resp.Post.Value() + if post.Post.ID > 0 { + dest := RegReplace(r.URL.String(), `(([a-zA-Z0-9\.\-]+)?/post/)([a-zA-Z0-9\-\.@]+)`, `$1`) + dest += strconv.Itoa(post.Post.ID) + http.Redirect(w, r, dest, 302) + return + } else { + http.Redirect(w, r, apid, 302) + return + } + } + } m, _ := url.ParseQuery(r.URL.RawQuery) if len(m["edit"]) > 0 { state.Op = "edit_post" @@ -438,6 +493,32 @@ func GetComment(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { Render(w, "index.html", state) return } + if path := strings.Split(ps.ByName("commentid"), "@"); len(path) > 1 { + apid := ResolveId(r, "comment", path[0], path[1]) + if apid != "" { + resp, err := state.Client.ResolveObject(context.Background(), types.ResolveObject{ + Q: apid, + }) + if err != nil { + dest := apid + if os.Getenv("LEMMY_DOMAIN") == "" { + dest = RegReplace(dest, `https:\/\/([a-zA-Z0-9\.\-]+\/comment\/\d+)`, `/$1`) + } + http.Redirect(w, r, dest, 302) + return + } + comment, _ := resp.Comment.Value() + if comment.Comment.ID > 0 { + dest := RegReplace(r.URL.String(), `(([a-zA-Z0-9\.\-]+)?/comment/)([a-zA-Z0-9\-\.@]+)`, `$1`) + dest += strconv.Itoa(comment.Comment.ID) + http.Redirect(w, r, dest, 302) + return + } else { + http.Redirect(w, r, apid, 302) + return + } + } + } m, _ := url.ParseQuery(r.URL.RawQuery) if len(m["reply"]) > 0 { state.Op = "reply" diff --git a/state.go b/state.go index ed3ad28..cdaa921 100644 --- a/state.go +++ b/state.go @@ -596,22 +596,22 @@ func (state *State) GetPost(postid int) { }) if err != nil { state.Status = http.StatusInternalServerError + state.Error = err return - } else { - state.Posts = []Post{Post{ - PostView: resp.PostView, - State: state, - }} - if state.CommentID > 0 && len(state.Posts) > 0 { - state.Posts[0].Rank = -1 - } - state.CommunityName = resp.PostView.Community.Name - cresp := types.GetCommunityResponse{ - CommunityView: resp.CommunityView, - Moderators: resp.Moderators, - } - state.Community = &cresp } + state.Posts = []Post{Post{ + PostView: resp.PostView, + State: state, + }} + if state.CommentID > 0 && len(state.Posts) > 0 { + state.Posts[0].Rank = -1 + } + state.CommunityName = resp.PostView.Community.Name + cresp := types.GetCommunityResponse{ + CommunityView: resp.CommunityView, + Moderators: resp.Moderators, + } + state.Community = &cresp } func (state *State) GetCommunity(communityName string) { From 8c7aabab72e2a7409c4bd317d3047339b4cf2876 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Sun, 16 Jul 2023 13:45:40 -0400 Subject: [PATCH 05/32] spoiler fix, default search options --- routes.go | 2 +- state.go | 2 +- templates/frontpage.html | 4 +--- templates/main.html | 3 ++- templates/nav.html | 4 ++-- templates/sidebar.html | 1 + 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/routes.go b/routes.go index 7f690f1..b3cec93 100644 --- a/routes.go +++ b/routes.go @@ -140,7 +140,7 @@ var funcMap = template.FuncMap{ body = buf.String() body = strings.Replace(body, `$1$2") + body = RegReplace(body, `::: ?spoiler (.*?)\n([\S\s]*?):::`, "
$1$2
") return template.HTML(body) }, "rmmarkdown": func(body string) string { diff --git a/state.go b/state.go index cdaa921..9b5afab 100644 --- a/state.go +++ b/state.go @@ -544,7 +544,7 @@ func (state *State) Search(searchtype string) { search := types.Search{ Q: state.Query, Sort: types.NewOptional(types.SortType(state.Sort)), - ListingType: types.NewOptional(types.ListingType("All")), + ListingType: types.NewOptional(types.ListingType(state.Listing)), Type: types.NewOptional(types.SearchType(searchtype)), Limit: types.NewOptional(int64(25)), Page: types.NewOptional(int64(state.Page)), diff --git a/templates/frontpage.html b/templates/frontpage.html index 63637d1..ac291fd 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -29,9 +29,7 @@ {{ template "nsfw.html" }} {{ else }}
- {{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}} - {{ template "menu.html" . }} - {{ end}} + {{ template "menu.html" . }} {{ if .Error }}
diff --git a/templates/main.html b/templates/main.html index e2d6390..5cf680d 100644 --- a/templates/main.html +++ b/templates/main.html @@ -27,12 +27,13 @@ {{ template "nsfw.html" }} {{ else }}
- {{ if or (contains .Sort "Top") (and (not .PostID) (not .User) (not .Community) (not .Activities) (eq .Op ""))}} + {{ if or (.Query) (.SearchType) (and (not .PostID) (not .User) (not .Activities) (eq .Op ""))}} {{ template "menu.html" . }} {{ end}} {{ if or (ne .Query "") .Communities }}
{{ end }} - + diff --git a/templates/main.html b/templates/main.html index 5cf680d..2b58c48 100644 --- a/templates/main.html +++ b/templates/main.html @@ -139,7 +139,7 @@ {{ end }} {{ end }} - + {{ template "sidebar.html" . }}
{{ end }} diff --git a/templates/post.html b/templates/post.html index a404d4c..a562c4c 100644 --- a/templates/post.html +++ b/templates/post.html @@ -1,5 +1,5 @@ {{ if and (ne .State.Op "vote_post") (ne .State.Op "save_post") }} -
+
{{ if gt .Rank 0 }}
{{ .Rank }}
{{ end }} @@ -91,6 +91,17 @@ {{ if .State.PostID }} hide all child comments {{ end }} + {{ if and .State.Site .State.Site.MyUser.IsValid (not .State.Site.MyUser.MustValue.LocalUserView.LocalUser.ShowReadPosts) }} + + {{ end }}
From ed7d9422d7dff5b4377807d4b0a32ae48e397925 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Thu, 20 Jul 2023 20:28:07 -0400 Subject: [PATCH 08/32] no comment jerk --- public/style.css | 1 + public/utils.js | 2 +- templates/main.html | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/style.css b/public/style.css index b9eb6f9..6340191 100644 --- a/public/style.css +++ b/public/style.css @@ -292,6 +292,7 @@ form.savecomment { .children .morecomments { } .morecomments { + height: 20px; clear: left; margin: 0px 0px 10px 0px; font-size: 10px; diff --git a/public/utils.js b/public/utils.js index 48a1e87..802058e 100644 --- a/public/utils.js +++ b/public/utils.js @@ -145,7 +145,7 @@ function loadMoreComments(e) { e.target.parentNode.outerHTML = res + '' setup() } else { - e.target.parentNode.outerHTML = "" + e.target.parentNode.innerHTML = "" } }, function() { e.target.innerHTML = "loading failed" diff --git a/templates/main.html b/templates/main.html index 2b58c48..110bd75 100644 --- a/templates/main.html +++ b/templates/main.html @@ -3,7 +3,7 @@ {{if and .Posts .PostID }}{{ (index .Posts 0).Post.Name}} : {{.CommunityName}}{{else if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}} - +