Using routes.yaml to filter by year

Hi all, I’m rebuilding my Ghost + Next.js site to a pure Ghost theme. I have it set up on my current site that only posts from this year are published, and then you can “go back” to prior years with specific routes. I went scouring the internet for a bit for an answer but ultimately wound up out of luck, so I’m here.

I’ve managed to do this just fine with the api.browse function and a filter that looks something like this: getGhostPosts("published_at:<'2023-01-01 0:0:0'");, but I’m struggling to translate this over to the custom routing in the routes.yaml file. I can upload the file below, but nothing displays on the main page or the 2022 page.

Here’s my current routes.yaml file:

routes:

collections:
  /:
    permalink: /post/{slug}/
    template: index
    filter: published_at:>'2022-12-31 0:0:0'
  /2022/:
    permalink: /post/{slug}/
    template: index
    filter: published_at:<'2023-01-01 0:0:0'

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

Any help would be greatly appreciated (also, Iknow the 2022 one is going to technically show everything before 2022, but at the moment, none of my posts are older than that.

Are you trying to do this for a subset of years, or any year? If it’s any year, you can use {year} interpolation

routes:

collections:
  /:
    permalink: /post/{year}/{slug}/

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

Thanks! Though it looks like that’ll add the year into the permalink and not actually filter it on the homepage, correct?

I may have misspoken in my original post — what I’m trying to achieve is that on the homepage, you’d only see posts published in the current year.