I have the following collection routes setup following the docs:
collections:
/:
permalink: /{slug}/
template: index
/blog/:
permalink: /blog/{slug}/
template: blog
filter: primary_tag:blog
If I tag a post/page with the blog
tag and head to the url localhost/blog/post
it just redirects the URL back to the original url of localhost/post
? Am I doing something wrong here?
Doesn’t work on already created slugs. Once you change the slug even a fraction it starts to work. Heads up - create new posts.
Got to admit, the routes.yaml should be turned into some kind of UI.
I think you need to be more precise with your collection definitions. Collections are assembled in the order they appear in the routes file. If a post matches the criteria of the first collection that’s where it’ll reside. In your definitions the first collection doesn’t have any filtering, meaning that technically all posts will go into this collection, leaving none left for your blog. Being more specific will solve your issue:
collections:
/:
permalink: /{slug}/
template: index
filter: primary_tag:-blog
/blog/:
permalink: /blog/{slug}/
template: blog
filter: primary_tag:blog
The first collection here is filtering for any post that doesn’t have ‘blog’ as the primary tag. This will leave the posts with the primary tag of ‘blog’ to fall into the /blog/ collection.
Hope this helps!
@DavidDarnes Thanks for this, got it working with the following code:
routes:
/: index
collections:
/blog/:
permalink: /blog/{slug}/
template: blog
filter: primary_tag:blog
Have to admit, routes have been the worst thing about Ghost so far. Needs a really good look at to make it overall a lot easier for users.
@DavidDarnes Any reason why it doesn’t work for pages tagged with blog
?
That routes file looks good to me, except for the indentation (guessing the forum editor has done something to it).
Tagging pages with “blog” seems a bit counterintuitive to me