The discussion revolves around redirecting non-logged-in users to /categories instead of /latest on a Discourse forum. JSey initiates the topic, seeking a way to customize the homepage behavior. codinghorror shares an example from community.imgur.com, where anonymous users are directed to /categories. JSey attempts a solution using JavaScript but encounters issues with the logo link. riking provides a patch and code snippet using HomeLogoComponent to set the target URL to /latest. Yuun confirms it works, and glynhudson asks how to implement it. riking suggests pasting the script in the CSS/HTML section. JSey reports the code breaks with a new header, and Falco shares a workaround using window.goToPortal. eviltrout introduces a new widget setting to customize the URL via a plugin, which is later refined in a commit. Falco tests the plugin-based solution, and eviltrout provides a fix. The discussion concludes with Falco testing the updated solution.
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?
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.
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 ‘/’?
Trying to figure out how to import DiscourseURL now… if anyone has hints, I will be glad…
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.
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.