mirror of
https://github.com/rystaf/mlmym.git
synced 2024-12-28 11:08:56 +00:00
Open links in new window (#84)
* Adding boolean setting to open links in new window and the implementation on posts and thumbnails * Fixing template syntax * Adding entry on settings form for links in new window Adding environment variable LINKS_IN_NEW_WINDOW for default setting resolves #52 --------- Co-authored-by: Nicolas Lanaro <nicolas.lanaro@thirdpartytrust.com>
This commit is contained in:
parent
8ccb9d95b9
commit
54bc355017
|
@ -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
routes.go
12
routes.go
|
@ -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) {
|
||||
|
@ -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")
|
||||
|
|
1
state.go
1
state.go
|
@ -105,6 +105,7 @@ type State struct {
|
|||
ShowNSFW bool
|
||||
HideInstanceNames bool
|
||||
HideThumbnails bool
|
||||
LinksInNewWindow bool
|
||||
SubmitURL string
|
||||
SubmitTitle string
|
||||
SubmitBody string
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue