How to achive this organization using routes or other config?

Hey all, I have a problem with the configuration of my site. Any help or idea would be greatly wellcome.

We have 3 types of contente:

general news (noticias)
articles targeted to the asociated people (asociacion)
ant info about books (bibliografia).

What I would want to achieve is posting every article marked a noticias (news) tag in the Main board (/) of any kind just all articles that have a noticias tag.

Articles with a asociacion (association) primary tag in a /asociacion route.
Articlesa with a bibliografia (bibliography) primary tag in a /bibliografia route.

I tried this:

routes:

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: tag:-asociacion+tag:-bibliografia
  /asociacion/:
    permalink: /asociacion/{slug}/
    filter: tag:asociacion
  /bibliografia/:
    permalink: /bibliografia/{slug}/
    filter: tag:bibliografia
 
taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

It achives more or lest expected behaviour but, in the main page we cannot show articles tagged asociacion or bibliografia even if tagged with noticias as noticias is not their primary tag.

I have tried this other aproach

routes:

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: tag:noticias
  /asociacion/:
    permalink: /asociacion/{slug}/
    filter: tag:asociacion
  /bibliografia/:
    permalink: /bibliografia/{slug}/
    filter: tag:bibliografia
 
taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

But then in the main page there only are shown articles with noticias as their primary tag.
I beleive correct aproache is the first one, as noticias will be the most used content and it would be great to just use other primary tag when you want to target that audience.

The problem is (I think) that each article can have only one route (one url) so filters cannot classify it in two routes.
So may be you cannot achieve this using just routes.

May we achieve it using other approach? May be changen the index for the front page?

How can we get this behaviour?

I have discovered channels.

They seem like the way to go.
But it seems you cannot put a channel as the main page.

They work well if I put them under a sub route, but I cannot put the channel it the main page:

This works:

  /:
    permalink: /{slug}/
    template: index
    filter: tag:-asociacion+tag:-bibliografia   
  /noticias/:
    controller: channel
    permalink: /noticias/{slug}/
    filter: tag:noticias

Articles not in asociacion or bibliografia are assigne a /{slug} url.
And you can access news (tagged with noticias) that are published with a asociacion or bibliografia primary tag.

But you have to acces them as /noticias to get news that are publised them in the main page.

This does not work correctly.

  /:
    permalink: /{slug}/
    template: index
    filter: tag:noticias
  /noticias/:
    controller: channel
    permalink: /noticias/{slug}/
    filter: tag:-asociacion+tag:-bibliografia   

Hey @ariznaf,

I did my best to try and understand what you are after, and I think I have it. The following code does a few things:

  • Sets up 2 routes for /asociacion/ and /bibliografia/ as channels
  • These channels will only list posts with a primary tag of “asociacion” and “bibliografia” respectively
  • Creates a collection on the home page
  • This collection will only show posts tagged with “noticias”
  • The collection also sets the post URLs to be prefixed with their primary tag, which should give your the permalink structure you are after
routes:
  /asociacion/:
    controller: channel
    filter: primary_tag:asociacion
  /bibliografia/:
    controller: channel
    filter: primary_tag:bibliografia

collections:
  /:
    permalink: /{primary_tag}/{slug}/
    template: index
    filter: tag:noticias

Note that you’ll need to tag your posts with “noticias” in order for the post URL to be prefixed with the primary tag.

Hope this helps! Let us know how you get on :+1:

2 Likes

Thanks a lot.

May be it is similar to what you propose.

The only difference is that I only want /asociacion/slug and /bibliografĂ­a/slug for the asociacion and bibliografĂ­a primary tags.

With any other I would like just /slug.
It may serve to put all others under a /article/slug

The way you write it I think it will put any other article with tags under a /firsttag/slug permalink.
I woul like any that has not a /asociation or /bibliografĂ­a primary tag in the / permalink.

What I am trying (I know now that I read about channel) is using a noticas channel as the main page/landing page of the blog.
But I could not get it to work.

Your path is a different one that may work (using that /{primary_tag}/{slug} permalink.

Thank, I will try and feedback results.

I see what you mean. You could in that case create one other collection which accounts for everything that isn’t tagged with “noticias”, and place them on another index page. In the example below I’ve created an “/other/” index page which will only list posts that weren’t tagged with “noticias” and will set their URL to just use the slug. You can rename “other” to whatever you like:

routes:
  /asociacion/:
    controller: channel
    filter: primary_tag:asociacion
  /bibliografia/:
    controller: channel
    filter: primary_tag:bibliografia

collections:
  /:
    permalink: /{primary_tag}/{slug}/
    template: index
    filter: tag:noticias
  /other/:
    permalink: /{slug}/
    template: index
    filter: tag:-noticias
1 Like

Thanks a lot for your help.

The problem I see with your schema is that when you mark a post with noticias it hits the main page and the permalink is /slug.

When you want to retire a post from front page and remove the noticias tag its permalink changes to /other/slug.

Changing the url of an article seems not a good idea.

But you have provided me with the hints to do it correctly.
I think I have it working now.

Any post that have asociacion tag (any were not just in primary tag) gets a /asociation/slug url.
Same with bibliografia tag and /bibliografia/slug.
Any post that has not a bibliografia or asociacion tag gets a /others/slug url.
In the main page we only show posts tagged with noticias.

routes:
  /:
    controller: channel
    filter: tag:noticias
collections:
  /asociacion/:
    permalink: /asociacion/{slug}/
    template: index
    filter: tag:asociacion
  /bibliografia/:
    permalink: /bibliografia/{slug}/
    template: index
    filter: tag:bibliografia
  /others/:
    permalink: /others/{slug}/
    template: index

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

I have to test it thoroughly but it seems to be working now.

In the main page you see only the posts tagged with noticias and the ones not tagged with bibliografia or asociacion go to a /others/slug url.

urls do not change meanwhile you do not delete the asociacion or bibliografia tags or do not assign them to a post that did not have that tags.

It seems the correct way for me to have a front page of selected news.

It would be great to be able to use none as a pseudo tag to select posts with no tags, in routes and in the admin interface.

You cannot now select a post with no tags with a filter.

I have changed the way to show posts in the front page.

Instead of tagging them with noticias, I will use featured posts to show them in front page.
If a posts is marked as featured, will show in front page whatever collection it belongs to.
If it is not marked as featured, it will be shown in frontpage.
To do that it is enough to use the filter featured:true.

routes:
  /:
    controller: channel
    filter: featured:true
collections:
  /asociacion/:
    permalink: /asociacion/{slug}/
    template: index
    filter: tag:asociacion
  /bibliografia/:
    permalink: /bibliografia/{slug}/
    template: index
    filter: tag:bibliografia
  /others/:
    permalink: /others/{slug}/
    template: index

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

Really nice!

1 Like

Thank you David, your guidance has pointed me in the right direction.
I understand much better now routes configuration in ghost.

1 Like