I’ve rerouted my Source site (using @Cathy_Sarisky’s Routes Editor tool) so that I have a page as my homepage. But now my list of posts is stuck in an infinite loop, only showing the first twelve posts over and over again!
AllI want is for the newsletter page to look how it did before rerouting – i.e. twelve posts, a “see more” link, and then an infinite scroll of everything. Surely this should be quire simple – I’m not trying to reinvent the wheel, just move to another part of my site! – but I can’t get my head around it.
Here’s the routes yaml I’ve uploaded:
routes:
/:
template: page
data: page.work
collections:
/newsletter/:
permalink: /newsletter/{slug}/
template: home
order: published_at desc
taxonomies:
tag: /tag/{slug}/
author: /author/{slug}/
Does this make sense to anyone? I’m no coding expert, so it’s quite possible I’ve made some very obvious error!
Try setting your template to index instead of home for the newsletters route.
1 Like
Ooh, fast response – thank you!
Okay, so now the first twelve posts still repeat, but only once. And now the landing header has vanished! Surely there’s a way to simply keep the page as if it was still the homepage?
hi danielgray,
it looks like the homepage and newsletter collection are overlapping, which is why posts are duplicating. try giving the homepage a separate template and make sure the newsletter loop uses limit="12" and pagination. also double-check the permalink for the newsletter doesn’t conflict with /. this usually fixes the infinite posts issue.
Oh lordy that sounds more fiddly than I was hoping, but I’ll give it a go. Thank you for your advice!
So, if you decide to edit the theme code for Source, you’re going to see it make a bunch of #get requests. Those ignore routing, which creates problems. You need routing and pagination for infinite scroll to work correctly, the way it’s set up. The home and index pages run some javascript in the browser, that requests the next page (by appending /page/NN to the current page), grabs the posts, and inserts them into the current page. So, when you set the template to home, you get posts you aren’t expecting, because there are posts on the homepage that are not part of the actual routing for the page. Source has some extra code for page 2 that’s probably the source of the duplication when you set the template to index.
Other themes do obey routing – you might look at Casper or Ruby if you want something that works with routing without fussing.
(There are many things I love about Source, but disrespect for routing is not one of them.)
1 Like