Skip to content

Commit

Permalink
community block button, link rewrite improvements, more imgur thumbna…
Browse files Browse the repository at this point in the history
…ils #17
  • Loading branch information
rystaf committed Jul 15, 2023
1 parent 8d31cba commit 1dd8476
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
8 changes: 4 additions & 4 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ form.savecomment {
.morecomments a:hover {
text-decoration: underline;
}
.member {
.member, .block {
display: inline-block;
margin-bottom:3px;
}
.member input {
.member input, .block input {
font-size: 10px;
font-weight: bold;
display: inline-block;
Expand All @@ -320,10 +320,10 @@ form.savecomment {
bottom: 1px;
cursor: pointer;
}
.join input {
.join input, .block input {
background-color: green;
}
.leave input {
.leave input, .block.unblock input {
background-color: #cf6165;
}
.pending input {
Expand Down
27 changes: 21 additions & 6 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ var funcMap = template.FuncMap{
if re.MatchString(p.URL.String()) {
return p.URL.String() + "?format=jpg&thumbnail=96"
}
re = regexp.MustCompile(`^https:\/\/i.imgur.com\/([a-zA-Z0-9]+)\.([a-z]+)$`)
re = regexp.MustCompile(`^https:\/\/(i\.)?imgur.com\/([a-zA-Z0-9]{5,})(\.[a-zA-Z0-9]+)?`)
if re.MatchString(p.URL.String()) {
return re.ReplaceAllString(p.URL.String(), "https://i.imgur.com/${1}s.$2")
return re.ReplaceAllString(p.URL.String(), "https://i.imgur.com/${2}s.jpg")
}
if p.URL.IsValid() {
return "/_/static/link.png"
Expand All @@ -139,14 +139,17 @@ var funcMap = template.FuncMap{
}
converted := buf.String()
converted = strings.Replace(converted, `<img `, `<img loading="lazy" `, -1)
re = regexp.MustCompile(`!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)[ $]?`)
converted = re.ReplaceAllString(converted, `<a href="https://$2/c/$1">!$1@$2</a> `)
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(`href="\/(c\/[a-zA-Z0-9\-]+|(post|comment)\/\d+)`)
converted = re.ReplaceAllString(converted, `href="/`+host+`/$1`)
re = regexp.MustCompile(` !([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+) `)
converted = re.ReplaceAllString(converted, ` <a href="/$2/c/$1">!$1@$2</a> `)
re = regexp.MustCompile(`::: spoiler (.*?)\n([\S\s]*?):::`)
converted = re.ReplaceAllString(converted, "<details><summary>$1</summary>$2</details>")
return template.HTML(converted)
Expand Down Expand Up @@ -753,6 +756,18 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
CommunityID: communityid,
Follow: true,
})
case "block":
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
state.Client.BlockCommunity(context.Background(), types.BlockCommunity{
CommunityID: communityid,
Block: true,
})
case "unblock":
communityid, _ := strconv.Atoi(r.FormValue("communityid"))
state.Client.BlockCommunity(context.Background(), types.BlockCommunity{
CommunityID: communityid,
Block: false,
})
case "logout":
deleteCookie(w, state.Host, "jwt")
deleteCookie(w, state.Host, "user")
Expand Down
2 changes: 1 addition & 1 deletion templates/frontpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<title>{{ 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}}</title>
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
<link rel="stylesheet" href="/_/static/style.css?v=24">
<link rel="stylesheet" href="/_/static/style.css?v=25">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body {{ if .Dark }}class="dark"{{end}}>
Expand Down
2 changes: 1 addition & 1 deletion templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>{{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}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
<link rel="stylesheet" href="/_/static/style.css?v=24">
<link rel="stylesheet" href="/_/static/style.css?v=25">
</head>
<body{{ if .Dark }} class="dark"{{end}}>
<noscript>
Expand Down
2 changes: 1 addition & 1 deletion templates/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{{ end }}
{{ else if .Comments -}}
<li class="selected"><a href="">comments</a></li>
{{ else if .Activities }}
{{ else if and .Activities (not .Query) }}
<li class="selected"><a href="">mailbox</a></li>
{{ else }}
<li{{ if eq .Sort "Hot" }} class="selected"{{end}}><a href="{{ .SortBy "Hot" }}">hot</a></li>
Expand Down
8 changes: 7 additions & 1 deletion templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ <h1>{{ if ne .Community.CommunityView.Community.Title ""}}{{ .Community.Communit
<input name="op" type="submit" value="{{ membership .Community.CommunityView.Subscribed}}">
<input name="communityid" type="hidden" value="{{ .Community.CommunityView.Community.ID }}">
</form>
<form method="POST" class="block {{ if .Community.CommunityView.Blocked }}unblock{{end}}">
<input name="op" type="submit" value="{{ if .Community.CommunityView.Blocked}}unblock{{else}}block{{end}}">
<input name="communityid" type="hidden" value="{{ .Community.CommunityView.Community.ID }}">
</form>
{{ end }}
{{ .Community.CommunityView.Counts.Subscribers }} readers <br>
<div>
{{ .Community.CommunityView.Counts.Subscribers }} readers
</div>
<span class="green" title="Users active in the last day"></span>
{{ .Community.CommunityView.Counts.UsersActiveDay }} users here now
{{ if and .Session (isMod .Community .Session.UserName) }}
Expand Down

0 comments on commit 1dd8476

Please sign in to comment.