Closed johanolofolsson closed 5 years ago
And this wasn't happening with Middleman 4.2.x?
It looks like it's returning the tag and a list of articles with that tag. Which seems reasonable. I don't remember the documented API. The blog extension is normally released by others. Was there a blog update recently?
Hi Thomas,
Thanks for the reply. This was happening in 4.2.1 as well, I updated to 4.3.2 yesterday to see if it resolved anything (I got SassC working in 4.2.x before your 4.3.x update, so I had put off the update until now).
Ah, I think you're right, I'm trying to do something here that differs too much from the boilerplate code in the documentation:
<% blog.tags.each do |tag, articles| %>
. I essentially want to only list tags (and not posts). Re-reading the docs, I see I missed this bit:
you can get a list of all tags with their associated articles from
blog.tags
.
So naturally the method spits out a map in my badly-written loop.
So user-error on my part ;). I'll mark this as closed and approach this a little differently.
Cheers again, Johan
<% blog.tags.each do |tag, _| %>
If you want to omit the articles
Nice, I didn’t know about that _
syntax. Thanks!
In case anyone stumbles upon this closed issue, here is what I ended up with (markup needs work, but it's the ERB code that counts):
<ul class="o-list-bare c-topic-list">
<% blog.tags.sort.each do |topic, _| %><%# Discard articles with `_` (thanks tdreyno: https://github.com/middleman/middleman-blog/issues/372#issuecomment-462506361) %>
<li class="o-list-bare__item c-topic-list__item">
<a href="<%= tag_path(topic) %>" class="c-link-muted c-topic-list__link"><%= topic %></a>
</li>
<% end %>
</ul>
Even if you don't want to list each tag's article, you could always iterate through articles
anyway to increment a counter. You can then display the number of articles per tag:
<ul class="o-list-bare c-topic-list">
<% blog.tags.sort.each do |topic, articles| %>
<li class="o-list-bare__item c-topic-list__item">
<% postCount = 0 %>
<% articles.each do |post| %>
<% postCount = postCount + 1 %>
<% end %>
<a href="<%= tag_path(topic) %>" class="c-link-muted c-topic-list__link c-topic"><span class="c-topic__label"><%= topic %></span> <span class="c-topic__count"><%= postCount %></span></a>
</li>
<% end %>
</ul>
Cheers, Johan
Hi gang,
The latest version of Middleman is great, the move to SassC has really sped things up. However for Middleman-blog, I'm getting some strange output when I try to loop through
blog.tags
.Expected behavior
Following https://middlemanapp.com/basics/blogging/#listing-articles (with some minor adjustments), I'm hoping to alphabetically list all of the tags present in all posts, using
blog.tags
.Actual behaviour
Although it correctly prints the current tag, it prints out other items of frontmatter as well:
Viewing the source, it's actually printing:
Steps to reproduce the problem
Troubleshooting
Additional information
Blog posts are actually suffixed
.html.md.erb
, as I intend to use erb-partials in these in the future. I've tried testing just.html.md
, but the same issue occurs: 2019-02-02-Test-Title.txtMy config.rb looks like this: config.txt
Many thanks for looking into the issue. I'm sure I've done something dumb, but I am at a complete loss as to what it is.
Cheers, Johan