Redirect / for non-logged in users?

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?

1 Like

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.

1 Like

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

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…

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>
5 Likes

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

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

1 Like

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

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>
1 Like

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

https://github.com/JSey/logo-click

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

4 Likes

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

3 Likes

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

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

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.

3 Likes

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 http://openenergymonitor.org/emon/forum

1 Like

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?!

It’s broke because the new header.

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

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

https://github.com/discourse/discourse/commit/02f771e66ead3fb6e861bfa1fd41d8c65d10ab1d

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.

7 Likes

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?