Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open links in new window #84

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ docker run -it -e LEMMY_DOMAIN='lemmydomain.com' -p "8080:8080" ghcr.io/rystaf/m
| LISTING | All |
| SORT | Hot |
| COMMENT_SORT | Hot |
| LINKS_IN_NEW_WINDOW | false |

12 changes: 12 additions & 0 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ func Initialize(Host string, r *http.Request) (State, error) {
if state.Listing == "" || state.Session == nil && state.Listing == "Subscribed" {
state.Listing = getenv("LISTING", "All")
}
if linksInNewWindow := getCookie(r, "LinksInNewWindow"); linksInNewWindow != "" {
state.LinksInNewWindow = linksInNewWindow != "0"
} else {
state.LinksInNewWindow = os.Getenv("LINKS_IN_NEW_WINDOW") != ""
}
return state, nil
}
func GetTemplate(name string) (*template.Template, error) {
Expand Down Expand Up @@ -765,6 +770,13 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
setCookie(w, "", "HideThumbnails", "0")
state.HideInstanceNames = false
}
if r.FormValue("linksInNewWindow") != "" {
setCookie(w, "", "LinksInNewWindow", "1")
state.LinksInNewWindow = true
} else {
setCookie(w, "", "LinksInNewWindow", "0")
state.LinksInNewWindow = false
}
state.Listing = r.FormValue("DefaultListingType")
state.Sort = r.FormValue("DefaultSortType")
state.CommentSort = r.FormValue("DefaultCommentSortType")
Expand Down
1 change: 1 addition & 0 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type State struct {
ShowNSFW bool
HideInstanceNames bool
HideThumbnails bool
LinksInNewWindow bool
SubmitURL string
SubmitTitle string
SubmitBody string
Expand Down
10 changes: 8 additions & 2 deletions templates/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@
</div>
{{ if not .State.HideThumbnails }}
<div class="thumb">
<a class="url" href="{{ if .Post.URL.IsValid }}{{ .Post.URL }}{{ else }}/{{ .State.Host }}/post/{{ .Post.ID }}{{ end }}">
<a class="url"
href="{{ if .Post.URL.IsValid }}{{ .Post.URL }}{{ else }}/{{ .State.Host }}/post/{{ .Post.ID }}{{ end }}"
{{ if .State.LinksInNewWindow }} target="_blank" {{ end }}>
<div {{ if and .Post.NSFW (not (and .State.Community .State.Community.CommunityView.Community.NSFW))}}class="img-blur"{{end}} style="background-image: url({{thumbnail .Post}})"></div>
</a>
</div>
{{ end }}
<div class="entry">
<div class="title">
<a class="url" href="{{ if .Post.URL.IsValid }}{{ .Post.URL }}{{ else }}/{{ .State.Host }}/post/{{ .Post.ID }}{{ end }}">{{ rmmarkdown .Post.Name }}</a>
<a class="url"
href="{{ if .Post.URL.IsValid }}{{ .Post.URL }}{{ else }}/{{ .State.Host }}/post/{{ .Post.ID }}{{ end }}"
{{ if .State.LinksInNewWindow }} target="_blank" {{ end }}>
{{ rmmarkdown .Post.Name }}
</a>
({{ domain . }})
</div>
<div class="expando-button{{ if and (not (and .Post.Body.IsValid .Post.Body.String )) (not (isImage .Post.URL.String)) }} hidden{{else if eq .Rank 0}} open{{ end }}"></div>
Expand Down
6 changes: 6 additions & 0 deletions templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@
</label>
<input type="checkbox" name="hideThumbnails" {{ if .HideThumbnails }}checked{{end}}>
</div>
<div>
<label>
open links in new window
</label>
<input type="checkbox" name="linksInNewWindow" {{ if .LinksInNewWindow }}checked{{end}}>
</div>
<div>
<label>lemmy: {{ .Site.Version }}<br><a href="https://github.com/rystaf/mlmym">mlmym</a>: {{ .Version }}</label>
<input type="submit" value="save">
Expand Down