community block button, link rewrite improvements, more imgur thumbnails #17

This commit is contained in:
Ryan Stafford 2023-07-15 11:12:10 -04:00
parent 8d31cbada5
commit 1dd8476fae
6 changed files with 35 additions and 14 deletions

View file

@ -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;
@ -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 {

View file

@ -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"
@ -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)
@ -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")

View file

@ -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}}>

View file

@ -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>

View file

@ -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>

View file

@ -91,8 +91,14 @@
<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) }}