Redirect / for non-logged in users?


(Joe Seyfried) #1

Not really sure if this has been discussed before - and also not if this is more “feature request” or more “extensibility”. Since I feel this is something others might have considered, I wanted to ask you guys here: In my opinion, it would make major sense to send all anonymous traffic landing on my page directly to /categories instead of /latest.

For the registered users in my community, it makes more sense to show them what happened lately - but for the public, it’s much better to show them the structure of what’s going on. I could even imagine a (custom) profile setting for each user where they can specify where they want to land when they go to http://example.com - depending on their favourite mental structure either categories, or latest (or even unread or new or…).

I wonder if this can be easily (or not-so-easily) be achieved by a custom user script, plugin or extension of the core functionality?


(Jeff Atwood) #2

You can see how they do it at community.imgur.com note that first load is always categories, but subsequent clicks or taps on the logo send you to latest. It is an interesting compromise.


Rationale Behind Latest As Default Homepage View
(Joe Seyfried) #3

That’s great indeed… Is there an easy way to tweak the link for the logos into https://…/latest?


(Joe Seyfried) #4

Hm… here’s how far I got:

<script>
  Discourse.HomeLogoComponent.reopen({
   linkUrl: function() {
       return Discourse.getURL('/latest');
   }.property(),   
  });
</script>

Which works pretty well, since I get this a tag on my logo:

<a data-auto-route="true" href="/latest">

but: if I click on the logo image, it takes me to Discourse.getURL('/'); (i.e. www.example.com instead of www.example.com/latest) in spite of the correct href attribute?! Wut?? Oh.

  click: function(e) {
    // if they want to open in a new tab, let it so
    if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) { return true; }

    e.preventDefault();

    DiscourseURL.routeTo('/');
    return false;
  }

Really? You define a property linkUrl and override click events to a hard-coded ‘/’? :smiley:

Trying to figure out how to import DiscourseURL now… if anyone has hints, I will be glad…


(Kane York) #5

This patch should do it:

https://github.com/discourse/discourse/pull/3799

<script>
  var HomeLogoComponent = require('discourse/components/home-logo').default;
  HomeLogoComponent.reopen({
   targetUrl: function() {
       return '/latest';
   }.property(),   
  });
</script>

alternate form:

<script>
define('discourse/pre-initializers/change-home-logo', ["exports", "discourse/components/home-logo"],
function(ex, hlModule) {
var HomeLogoComponent = hlModule.default;
ex["default"] = {
  name: "change-home-logo",
  initialize: function(container) {
    HomeLogoComponent.reopen({
      targetUrl: function() {
       return '/latest';
      }.property(),
    });
  }
}});
</script>

User-selectable default home view preference
(Joe Seyfried) #6

Do you know when this PR will pass? Probably the spurious Travis failure prevents further actions?


(Kane York) #7

Nope, we’re doing the release right now :wink:


(Joe Seyfried) #8

Okay, noticed that. Just keep on! And thanks!! :smiley:


(Rafael dos Santos Silva) #9

Haha I was doing an ugly hack because I want to redirect to main site when on discourse main page, this is wonderful!

<script type="text/javascript">

  var goToPortal = function() { 
      if (window.location.href === 'https://example.com.br/forum/') { 
          window.location = 'https://example.com.br';
      }
  };
  
  Discourse.HeaderView.reopen({
  didInsertElement : function(){
    this._super();
    Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
  },
  afterRenderEvent : function(){
    var logo = $('img#site-logo.logo-big').parent()[0];
  
    logo.addEventListener('click', goToPortal, false);
  }
});
</script>

(Joe Seyfried) #10

While I waited for that PR, and since I needed the functionality, I threw together this:

…I am reluctant to open a plugin topic for this, since it is so tiny… If you find it useful, enjoy.


Rationale Behind Latest As Default Homepage View
(Régis Hanol) #11

FYI: I just merged @riking’s PR :wink:


(Sam) #12

And it works quite nicely! Thanks @riking and @JSey for your little plugin that I’ve been using up until now. :grinning:


(Glynhudson) #13

Now that his patch has been integrated how can I implement on my site? I would like to direct logo click to /latest and make categories the first landing page to help new users.

Thanks


(Sam) #14

Just copy and paste riking’s script here into </head> in Admin -> Customize -> CSS/HTML to have the logo redirect to /latest.

To make categories the landing page, go to Admin -> Site Settings -> Basic Setup and make categories the first entry in the list for the top menu setting.


(Glynhudson) #15

Works a treat :smiley:

Thanks so much for quick reply.

My new forum setup is coming along nicely
http://community.openenergymonitor.org. So much nicer than our old Durpal 6
PHP setup Forums | Archived Forum


(Joe Seyfried) #16

Uh - and @Yuun’s code broke again:

Error: Could not find module discourse/components/home-logo

Where did that disappear to? Did a quick recursive grep, but came up with nothing?!


Help us test the new header code!
(Rafael dos Santos Silva) #17

It’s broke because the new header.


(Joe Seyfried) #18

Yup, seen that, thanks. I guess I will x-post my question there since it belongs to that new addition.


(Robin Ward) #19

I’ve added a new widget setting to customize that url in this commit:

Here’s an example of how to use it via a customization:

<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href', '/new-url')
</script>

Just replace /new-url whatever you want the path to be and you should be good to go.


Show 'Categories' to New Users, 'Latest' to Members 📈
(Rafael dos Santos Silva) #20

I want to change the behavior of the home logo only when users are at my home page (window.location === ‘example.com/forum/’).

Should passing a function as the third parameter work?