Usage of Internal Tags for routes.yaml

I am currently trying to divide my Ghost blog (version 3.12.1) into a “blog” and a “status” section. I had the idea to use internal tags to distinguish between the regular blog posts, and the shorter status posts that get rendered differently. Following that idea, I created the following routes.yaml file:

routes:
  /:
    data: page.home
    template: home
collections:
  /status/:
    permalink: /status/{id}/
    template: status
    filter: primary_tag:hash-status
    data: tag.hash-status
  /posts/:
    permalink: /post/{slug}/
    template: index
    filter: primary_tag:hash-post
    data: tag.hash-post
taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

Unfortunately that does not seem to work. Even when I assign the correct tags to the posts, I get a 404 for both URLs, “/status/” and “/posts/”. It seems that the foreach loop comes up empty:

{{#foreach posts}}
    {{> "index-post-entry"}}
{{/foreach}}

When I test it with regular, non-internal tags, everything works as expected. But then I would end up with a visible “post” and “status” tag – what I don’t really want.

I was first thinking of using {{#get}}...{{/get}} to query the posts, as a workaround, but that is missing the pagination, which would also be not an option for me.

Am I doing something wrong, or is what I am trying to achieve currently not possible? Any input welcome. Thanks!

Just tested your routing on my end. Here is how I got it working.

  1. It seems like 404 is related with data: tag.hash-status. When I remove the line, it doesn’t throw 404. I assume it’s because internal tags don’t have data (name, slug and description) like regular tags.
  2. Then I updated the filter to use tag:hash-status instead of primary_tag.

Awesome, that did it! Thank you very much. Unfortunately, this causes another problem. Since it does not use the data for meta_title and meta_description, I now get “My awesome blog (Page n)” as a title on the index page.

Any idea how to get rid of it, without hardcoding the values in HTML?

I’m afraid there might not be any other way than hardcoding them when you’re using internal tags. How about using regular tags and hiding the tags with CSS?

Something like:

.post-tag-status,
.post-tag-post {
    display: none;
}

Thanks for your input! I really appreciated your quick answers and your thoughts :+1:

I thought about using CSS, too. But that would just be a cosmetic fix and a bit hacky. They would still be accessible under https://myblog.com/tag/status/ and also be visible when I list all the tags on the post page as well.

So not really an option for me :frowning_face:.

Hey @jbfriedrich, I was totally wrong with the assumption below. It still doesn’t work, but it doesn’t seem like the reason. Internal tags have as much data as regular tags. There must be another reason why it didn’t work.

Yes, that is also what I figured. The internal tags are supposed to be no different from the “normal” tags, from what I could read from the documentation and what I found on the web. I am not sure if it’s worth to open a GitHub issue. I don’t want to create unnecessary work for the Ghost Team.

Mayne @DavidDarnes has a suggestion.

Just had a play with the routes file you initially made. This is what I end up using:

routes:

collections:
  /status/:
    permalink: /status/{id}/
    template: status
    filter: tag:hash-status
    data:
      post: page.status
    
  /:
    permalink: /post/{slug}/
    template: index
    filter: tag:-hash-status

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

Rather than using tag data I’m using page data, which will give you a bit more control. You’ll need to modify the status.hbs template to make sure the content of the page is being exposed correctly. I’m also using the filters to mirror each other, so the status page only shows posts with the internal status tag and the home page show ever other type of post. Bit more streamlined than adding an internal tag to every single post.

Hope this helps!

1 Like

Hi @DavidDarnes! Thanks a lot for your quick input, it is very much appreciated. I tried using a page, too, but it makes things very messy and sometimes I get an empty page, where the posts are supposed to be. It was a wild ride with a lot of testing the last couple of days :slight_smile:.

Just in general, it should work only with tags, shouldn’t it? Are @minimaluminium and I reading the documentation wrong? I am trying to understand whats going on and why the data from the public tags can be used, but the private/internal tags fail to render, even though you can specify a description, meta data and title etc. in the Ghost admin UI.

The routing feature might need some more love. Do you think it would be beneficial to create a GitHub issue for this? There is also another issue that is related. The link to the RSS is not generated properly in {{ghost_head}} when I use my routes.yaml file. It creates a link without a proper href to the RSS feed. The RSS feed itself works fine, but as its not linked properly in the header. Tools have a problem finding the feed.

The empty page issue could be because your page slug and the collection slug are the same, I encountered that issue while I tested this locally :sweat_smile:.

That could be possible, I won’t rule that out firsthand. I would need to test again :grinning:.

But the question still remains: Is the internal tag behaviour that we experience here intentional, or is it a bug? If it is a bug, would a bug report on Github help, or would that be counter-productive as the team is aware and its on an internal list somewhere? :grin:

@jbfriedrich it does sound like a bug, or at least an inconsistency with our implementation/docs. An issue would be helpful :slight_smile:

2 Likes

Thanks @Kevin! :slight_smile: I will file an issue until Friday on Github then :+1:.

hi @jbfriedrich, did you eventually file an issue for this? I’ve been looking into the repo but I could not find anything related to this topic. I am facing exactly your problem, not being able to fetch the meta_title and meta_description on the index page for collections. I’ve been trying both with internal and public tags, but it doesn’t make any difference. Here’s my routes.yaml, if it is of any help for the Ghost staff:

routes:
  /: home
  /signup/: members/signup
  /signin/: members/signin
  /account/: members/account

collections:
  /blog/:
    permalink: /blog/{slug}/
    filter: tag:blog+tag:-magazine
    template: index
    data: tag.blog
  /magazine/:
    permalink: /magazine/{slug}/
    filter: tag:magazine+tag:-blog
    template: index
    data: tag.magazine
taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

Looks like @jbfriedrich was planning on reporting the issue, but I can’t see it yet on GitHub.

As a work around you could create a page that can be used to manage the content of that route, as shown in my previous comment:

Hey guys! Sorry for the late reply, I did not have a chance yet to create that issue :cry:. Sorry about that, but it has been a couple of busy weeks due to current events and work that came in the way.

I was just able to finish my “theme” and set up the blog the way I want it to. Next step is to gather all the info and file the issue on Github. My plan is to do it this week, if nothing unforseen happens in the meantime. Sorry again!

2 Likes

Hey @jbfriedrich, I am not in a hurry and in the meantime, I can give it a try to the workaround @DavidDarnes (thanks for that!) suggested

1 Like

Hey David, I’m working through the exact issue outlined in this thread, but I think I’m getting caught up on this line in your directions. What does it mean to expose the content of the page correctly?

In my case, the desired result is simple. I have a blog, which I populate with posts tagged #blog (slug being hash-blog).

collections:
  /blog/:
    permalink: /blog/{slug}/
    template: blog
    filter: tag:hash-blog
    data: 
      post: page.blog

Using this, I can’t even load my site. Chrome gives me this:

localhost redirected you too many times.

My blog.bhs:

{{!< default}}
    <div class="section">
            <div class="column is-two-thirds is-full-mobile" >
                {{#foreach posts}}
                    {{>post_card}}
                {{/foreach}}
                <!-- pagination -->
                <div class="container">
                    {{pagination}}
                </div>
            </div>
    </div>

This is driving me nuts. Ideally, I’d be able to use data: tag.hash-blog and pull the meta title and description as they are set in the CMS. I see there may or may not be an open issue for that. In the meantime, any help you can lend to get your workaround functioning would be great!

Hmm, my first guess is that you’ve created a page called blog with the same slug as the collection name. This might be why there’s a redirect loop happening, because it’s not sure whether to show the page or the collection page. Try changing the page slug to blogpage and then assigning the post data to page.blogpage.

You may also need to add a redirect in for the blogpage URL so it redirects to blog, however Ghost may sort that for you (I can’t remember off the top of my head).

Thank you so much! Now one of your earlier comments makes much more sense to me.

For what it’s worth, I did not have to set up any redirects. Ghost seemingly handled that for me.

Cheers!

1 Like