Add configurable front page (anonymous discover view) behaviour (#1103)

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: #1103
Reviewed-by: lyse <lyse@noreply@mills.io>
lists_ui
James Mills 1 month ago
parent a12b53322e
commit f3f1e42974
  1. 19
      cmd/yarnd/main.go
  2. 3
      internal/config.go
  3. 2
      internal/context.go
  4. 5
      internal/langs/active.en.toml
  5. 20
      internal/langs/active.zh-CN.toml
  6. 20
      internal/langs/active.zh-TW.toml
  7. 38
      internal/langs/translate.zh-CN.toml
  8. 38
      internal/langs/translate.zh-TW.toml
  9. 5
      internal/manage_handlers.go
  10. 11
      internal/options.go
  11. 13
      internal/theme/templates/managePod.html
  12. 22
      internal/view_handlers.go

@ -86,13 +86,15 @@ var (
adminEmail string
// Pod Settings
frontPage string
openProfiles bool
openRegistrations bool
disableGzip bool
disableLogger bool
disableMedia bool
disableFfmpeg bool
disableArchive bool
disableGzip bool
disableLogger bool
disableMedia bool
disableFfmpeg bool
disableArchive bool
// Pod Limits
twtsPerPage int
@ -170,6 +172,11 @@ func initFlags() {
&openProfiles, "open-profiles", "O", internal.DefaultOpenProfiles,
"whether or not to have open user profiles",
)
flag.StringVar(
&frontPage, "front-page", internal.DefaultFrontPage,
"sets the behaviour of the front page (anonymous discover view)",
)
flag.BoolVar(
&disableGzip, "disable-gzip", internal.DefaultDisableGzip,
"whether or not to disable Gzip compression",
@ -377,8 +384,10 @@ func main() {
internal.WithAdminEmail(adminEmail),
// Pod Settings
internal.WithFrontPage(frontPage),
internal.WithOpenProfiles(openProfiles),
internal.WithOpenRegistrations(openRegistrations),
internal.WithDisableGzip(disableGzip),
internal.WithDisableLogger(disableLogger),
internal.WithDisableMedia(disableMedia),

@ -57,6 +57,8 @@ type Settings struct {
OpenProfiles bool `yaml:"open_profiles"`
OpenRegistrations bool `yaml:"open_registrations"`
FrontPage string `yaml:"front_page"`
// XXX: Deprecated fields (See: https://git.mills.io/yarnsocial/yarn/pulls/711)
// TODO: Remove post v0.14.x
BlacklistedFeeds []string `yaml:"blacklisted_feeds"`
@ -116,6 +118,7 @@ type Config struct {
Description string
Store string `json:"-"`
StartPage string
FrontPage string
Theme string `json:"-"`
AlertFloat bool
AlertGuest bool

@ -62,6 +62,7 @@ type Context struct {
MediaResolution int
RegisterDisabled bool
OpenProfiles bool
FrontPage string
DisableMedia bool
DisableFfmpeg bool
PermittedImages []string
@ -275,6 +276,7 @@ func NewContext(s *Server, req *http.Request) *Context {
MediaResolution: conf.MediaResolution,
RegisterDisabled: !conf.OpenRegistrations,
OpenProfiles: conf.OpenProfiles,
FrontPage: conf.FrontPage,
DisableMedia: conf.DisableMedia,
DisableFfmpeg: conf.DisableFfmpeg,
LastTwt: types.NilTwt,

@ -353,7 +353,6 @@ PermalinkNothingFound = "<p>Nothing to see here. <a href=\"?unfiltered=1\">View
ProfileAtomLinkTitle = "Atom"
ProfileBookmarksLinkTitle = "Bookmarks"
ProfileConfigLinkTitle = "Config"
ProfileMayNotFollowYou = "may not follow you"
ProfileFollowersLinkTitle = "Followers"
ProfileFollowingLinkTitle = "Following"
ProfileFollowsYou = "follows you"
@ -362,6 +361,7 @@ ProfileIsMuted = "User currently muted"
ProfileLastPosted = "last posted"
ProfileLastSeen = "Last seen"
ProfileLinks = "User Links"
ProfileMayNotFollowYou = "may not follow you"
ProfileMuteLinkTitle = "Mute"
ProfileMuteUser = "You are free to Unfollow or Mute this user or feed.&#10;Muting will also remove that user/feed's content from your view.&#10;You will no longer see content from that user/feed anywhere."
ProfileNoDescription = "No description provided."
@ -414,6 +414,9 @@ SettingsFormDisplayImagesPreferenceGallery = "Gallery"
SettingsFormDisplayImagesPreferenceInline = "Inline (default)"
SettingsFormDisplayImagesPreferenceLightbox = "Lightbox"
SettingsFormDisplayImagesPreferenceTitle = "Display Images As"
SettingsFormFrontPageAll = "all posts in cache"
SettingsFormFrontPageLocal = "local posts only"
SettingsFormFrontPageTitle = "Front page displays"
SettingsFormOpenLinksInPreferenceNewWindow = "New window (default)"
SettingsFormOpenLinksInPreferenceSameWindow = "Same window"
SettingsFormOpenLinksInPreferenceTitle = "Open Links In"

@ -1418,10 +1418,6 @@ other = "Bookmarks"
hash = "sha1-8851142da56fd885ce668a165b33fee7003e858d"
other = "配置"
[ProfileDoesNotFollowYou]
hash = "sha1-3e9436055805b0093be35787f9ed73099eec0ad0"
other = "may not follow you"
[ProfileFollowersLinkTitle]
hash = "sha1-78eaabf4a629795fe52f523f44f5000c6b204f2f"
other = "Followers"
@ -1454,6 +1450,10 @@ other = "Last seen"
hash = "sha1-96348083f320cb5fc4ea1736274b4072f6277689"
other = "User Links"
[ProfileMayNotFollowYou]
hash = "sha1-3e9436055805b0093be35787f9ed73099eec0ad0"
other = "may not follow you"
[ProfileMuteLinkTitle]
hash = "sha1-0f0973483d912464153b3be374a94b58e6cd0ef6"
other = "禁言"
@ -1662,6 +1662,18 @@ other = "Lightbox"
hash = "sha1-e51d60bd693b10dc7da750381a02d6b90846057a"
other = "Display Images As"
[SettingsFormFrontPageAll]
hash = "sha1-563dcd61f244e3684535aa54fdd574be7a642a59"
other = "all posts in cache"
[SettingsFormFrontPageLocal]
hash = "sha1-06c500968fa079d987f1672b5714d790def29211"
other = "local posts only"
[SettingsFormFrontPageTitle]
hash = "sha1-29fbad2d5dd4550f50d7eb29b5a5722230ca653e"
other = "Front page displays"
[SettingsFormOpenLinksInPreferenceNewWindow]
hash = "sha1-b1a8bf37d9ca8643193b898991289deb3b77bcf9"
other = "New window (default)"

@ -1418,10 +1418,6 @@ other = "Bookmarks"
hash = "sha1-8851142da56fd885ce668a165b33fee7003e858d"
other = "配置"
[ProfileDoesNotFollowYou]
hash = "sha1-3e9436055805b0093be35787f9ed73099eec0ad0"
other = "may not follow you"
[ProfileFollowersLinkTitle]
hash = "sha1-78eaabf4a629795fe52f523f44f5000c6b204f2f"
other = "Followers"
@ -1454,6 +1450,10 @@ other = "Last seen"
hash = "sha1-96348083f320cb5fc4ea1736274b4072f6277689"
other = "User Links"
[ProfileMayNotFollowYou]
hash = "sha1-3e9436055805b0093be35787f9ed73099eec0ad0"
other = "may not follow you"
[ProfileMuteLinkTitle]
hash = "sha1-0f0973483d912464153b3be374a94b58e6cd0ef6"
other = "禁言"
@ -1662,6 +1662,18 @@ other = "Lightbox"
hash = "sha1-e51d60bd693b10dc7da750381a02d6b90846057a"
other = "Display Images As"
[SettingsFormFrontPageAll]
hash = "sha1-563dcd61f244e3684535aa54fdd574be7a642a59"
other = "all posts in cache"
[SettingsFormFrontPageLocal]
hash = "sha1-06c500968fa079d987f1672b5714d790def29211"
other = "local posts only"
[SettingsFormFrontPageTitle]
hash = "sha1-29fbad2d5dd4550f50d7eb29b5a5722230ca653e"
other = "Front page displays"
[SettingsFormOpenLinksInPreferenceNewWindow]
hash = "sha1-b1a8bf37d9ca8643193b898991289deb3b77bcf9"
other = "New window (default)"

@ -1,31 +1,11 @@
[FilterTitle_clear]
hash = "sha1-381c4bf1d409c0271f73195c2f3c68225ec7c00c"
other = "Clear Filters"
[SettingsFormFrontPageAll]
hash = "sha1-563dcd61f244e3684535aa54fdd574be7a642a59"
other = "all posts in cache"
[FilterTitle_excludeme]
hash = "sha1-102b6213d2e069f6ea8e10dbfe22f1fe32dd3496"
other = "Hide my posts"
[SettingsFormFrontPageLocal]
hash = "sha1-06c500968fa079d987f1672b5714d790def29211"
other = "local posts only"
[FilterTitle_localonly]
hash = "sha1-7a28a960d5020f90caae43f2c6a297527e5953ba"
other = "Only {{ .InstanceName }}"
[FilterTitle_mentionsme]
hash = "sha1-85e12bc6f2e56024e47cc826a14968247a52dc54"
other = "Mentions"
[FilterTitle_nobots]
hash = "sha1-56dc31961dd1059fd2086c1b57c998ce7b5ed790"
other = "Hide Bots"
[FilterTitle_noreplies]
hash = "sha1-59c6bbf03b541b7f5e65ca704429a552b2e6988b"
other = "Without replies"
[FilterTitle_norss]
hash = "sha1-39b28771d9c1019cb39dba837bbf74f1fdd47dd5"
other = "Hide Feeds"
[ProfileDoesNotFollowYou]
hash = "sha1-3e9436055805b0093be35787f9ed73099eec0ad0"
other = "may not follow you"
[SettingsFormFrontPageTitle]
hash = "sha1-29fbad2d5dd4550f50d7eb29b5a5722230ca653e"
other = "Front page displays"

@ -1,31 +1,11 @@
[FilterTitle_clear]
hash = "sha1-381c4bf1d409c0271f73195c2f3c68225ec7c00c"
other = "Clear Filters"
[SettingsFormFrontPageAll]
hash = "sha1-563dcd61f244e3684535aa54fdd574be7a642a59"
other = "all posts in cache"
[FilterTitle_excludeme]
hash = "sha1-102b6213d2e069f6ea8e10dbfe22f1fe32dd3496"
other = "Hide my posts"
[SettingsFormFrontPageLocal]
hash = "sha1-06c500968fa079d987f1672b5714d790def29211"
other = "local posts only"
[FilterTitle_localonly]
hash = "sha1-7a28a960d5020f90caae43f2c6a297527e5953ba"
other = "Only {{ .InstanceName }}"
[FilterTitle_mentionsme]
hash = "sha1-85e12bc6f2e56024e47cc826a14968247a52dc54"
other = "Mentions"
[FilterTitle_nobots]
hash = "sha1-56dc31961dd1059fd2086c1b57c998ce7b5ed790"
other = "Hide Bots"
[FilterTitle_noreplies]
hash = "sha1-59c6bbf03b541b7f5e65ca704429a552b2e6988b"
other = "Without replies"
[FilterTitle_norss]
hash = "sha1-39b28771d9c1019cb39dba837bbf74f1fdd47dd5"
other = "Hide Feeds"
[ProfileDoesNotFollowYou]
hash = "sha1-3e9436055805b0093be35787f9ed73099eec0ad0"
other = "may not follow you"
[SettingsFormFrontPageTitle]
hash = "sha1-29fbad2d5dd4550f50d7eb29b5a5722230ca653e"
other = "Front page displays"

@ -43,6 +43,7 @@ func (s *Server) ManagePodHandler() httprouter.Handle {
twtsPerPage := SafeParseInt(r.FormValue("twtsPerPage"), s.config.TwtsPerPage)
avatarResolution := SafeParseInt(r.FormValue("avatarResolution"), s.config.AvatarResolution)
mediaResolution := SafeParseInt(r.FormValue("mediaResolution"), s.config.MediaResolution)
frontPage := r.FormValue("frontPage")
openProfiles := r.FormValue("enableOpenProfiles") == "on"
openRegistrations := r.FormValue("enableOpenRegistrations") == "on"
permittedImages := r.FormValue("permittedImages")
@ -116,6 +117,10 @@ func (s *Server) ManagePodHandler() httprouter.Handle {
s.config.AvatarResolution = avatarResolution
// Update Media Resolution
s.config.MediaResolution = mediaResolution
// Front Page behaviour (anonymous discover view)
s.config.FrontPage = frontPage
// Update open profiles
s.config.OpenProfiles = openProfiles
// Update open registrations

@ -78,6 +78,9 @@ const (
// DefaultOpenRegistrations is the default for open user registrations
DefaultOpenRegistrations = false
// DefaultFrontPage is the default behaviour of the pod's front page (anonymous discover view)
DefaultFrontPage = localViewKey
// DefaultDisableGzip is the default for disabling Gzip compression
DefaultDisableGzip = false
@ -440,6 +443,14 @@ func WithOpenRegistrations(openRegistrations bool) Option {
}
}
// WithFrontPage sets the behaviour of the pod's front page (anonymous discover view)
func WithFrontPage(frontpage string) Option {
return func(cfg *Config) error {
cfg.FrontPage = frontpage
return nil
}
}
// WithDisableGzip sets the disable Gzip flag
func WithDisableGzip(disableGzip bool) Option {
return func(cfg *Config) error {

@ -159,6 +159,19 @@
</label>
</fieldset>
</div>
<div class="grid">
<fieldset>
<legend>{{ tr . "SettingsFormFrontPageTitle" }}</legend>
<label for="local">
<input id="local" type="radio" name="frontPage" value="local" {{ if eq $.FrontPage "local" }}checked{{ end }}>
{{ tr . "SettingsFormFrontPageLocal" }}
</label>
<label for="all">
<input id="all" type="radio" name="frontPage" value="all" {{ if eq $.FrontPage "all" }}checked{{ end }}>
{{ tr . "SettingsFormFrontPageAll" }}
</label>
</fieldset>
</div>
<button type="submit" class="primary">{{ tr . "ManagePodUpdateButton" }}</button>
</form>
</article>

@ -22,6 +22,10 @@ func (s *Server) getDiscoverTwts(user *User) types.Twts {
return s.cache.GetByUserView(user, discoverViewKey, false, FilterNoOp)
}
func (s *Server) getLocalTwts(user *User) types.Twts {
return s.cache.GetByUserView(user, localViewKey, false, FilterNoOp)
}
func (s *Server) getMentionedTwts(user *User) types.Twts {
return s.cache.GetMentions(user, false)
}
@ -75,10 +79,24 @@ func (s *Server) TimelineHandler() httprouter.Handle {
fffs := GetFilterFuncFactories(r.URL.Query()["f"])
if !ctx.Authenticated {
var viewKey string
switch s.config.FrontPage {
case "local":
viewKey = localViewKey
case "all":
viewKey = discoverViewKey
default:
viewKey = localViewKey
}
if s.config.Features.IsEnabled(FeatureFilterAndLists) {
twts = s.cache.GetByUserView(ctx.User, discoverViewKey, false, fffs...)
twts = s.cache.GetByUserView(ctx.User, viewKey, false, fffs...)
} else {
twts = s.getDiscoverTwts(ctx.User)
if viewKey == discoverViewKey {
twts = s.getDiscoverTwts(ctx.User)
} else {
twts = s.getLocalTwts(ctx.User)
}
}
ctx.Title = s.tr(ctx, "PageLocalTimelineTitle")
} else {

Loading…
Cancel
Save