[Guide] Override the home page on a NodeBB
-
Woohoo! Is this a better option than an nginx rewrite?
Although I couldn't get the rewrite to work...it just led to a redirect loop. So will try this, despite no plugin creation experience.
-
Prior to the prerequisite commit, it was actually impossible, so this is an improvement, albeit only a slight one.
You can override the
/
route, to show/recent
,but it doesn't accept arguments yet, so it just loads that day's posts. Would be neat for it to be able to loadIt works! See my edit./category/1
, but that doesn't quite work.There are two steps to it:
- Overriding the route itself (in the
app.load
hook) - Overriding the custom mapping for ajaxification (non cold-loads)
Edit: Hm... actually, come to think of it, maybe there is a way...
Edit 2: Yep!
Above, I overwrote the
/
and/api/home
routes. You can do the following to "fake" a parameter being passed in, as the home route doesn't normally provide parameters.app.get('/', middleware.buildHeader, function(req, res, next) { req.params.term = 'month'; controllers.categories.recent.apply(controllers.categories.recent, arguments); }); app.get('/api/home', function(req, res, next) { req.params.term = 'month'; controllers.categories.recent.apply(controllers.categories.recent, arguments); });
- Overriding the route itself (in the
-
I don't suppose the ACP will ever have a "select homepage" option? I'm guessing that would be complicated to do though, since this is already.
-
Hmm, interesting. Nice tutorial @julian !
-
I don't suppose the ACP will ever have a "select homepage" option
I imagine it would be possible to do. It's something I've been wanting to do but haven't had the time for it yet
-
@sadmulwar The guide is for an outdated version of NodeBB, you should just try assigning the
/
route against the router... @baris or @psychobunny can confirm, but in your listener forstatic:app.load
:plugin.init = function(data, callback) { data.router.get('/', function(req, res) { // ... }); callback(); });
-
I appears the custom homepage plugin doesn't work well with ajaxify. If you ajaxify to the
/
route, it just goes to the categories page. However, if you cold load to/
, it goes to the custom homepage. Is there a way to fix this?Is there a hook to add possible routes to the "Home Page Route" dropdown in the ACP?
-
I haven't updated that plugin yet iirc, and we haven't built a hook for the ACP dropdown just yet, but its a good idea. PR?
-
You must code in your sleep, because the hook is definitely there already