Blog: list all tags, except those on "hidden" pages

Question: how can I create a list of article tags, but exclude tags for articles that are “hidden”?

Situation:

I’m building an agency website and I’m using Middleman Blog for both blogs and case studies. I’ve activated directory indexes. I currently have the following directory structure:

- cases
| - item-1
    | - item-1-image.jpg
    | - item-1-logo.png
| - item-1.html.erb
| - item-2
    | - item-2-image.jpg
    | - item-2-logo.png
        | - subitem-1
            | - index.html
| - item-2.html.erb

This gives me two “top-level” case studies and one that’s one level deeper. Reason for this is I want to show “item-1” and “item-2” directly on a portfolio page, but I want to hide “subitem-1”. That last one is only accessible from the “item-2”-page.

To do this, I’ve added “hide: true / false” to the article’s frontmatter. So that works; portfolio page only shows articles where “hide” is flagged “false”.

Say that the three items have the following tags:

item-1: "animation", "graphic design"
item-2: "graphic design"
  subitem1: "poster design"

Problem is, when I place the following code on portfolio page, all tags (including “poster design”) are listed:

<% blog('cases').tags.each do |tag, articles| %>
    <span><%= link_to "#{tag}", tag_path(tag, 'werk') %></span>
<% end %>

If I place the following code, each article’s tags are listed, meaning that “graphic design” is listed twice:

<% page_articles('werk').delete_if { |x| x.data.hide }.each do |item| %>
    <% item.tags.each do |tag, articles| %>
        <span><%= link_to "#{tag}", tag_path(tag, 'werk') %></span>
    <% end %>
<% end %>

I’m stuck. Anyone know a way so that in this example tags “animation” and “graphic design” are listed once, and “poster design” isn’t listed at all?

Thanks!

The repeated tags should be gone with uniq. In your second loop, it would look like:

<% page_articles('werk').delete_if { |x| x.data.hide }.uniq.each do |item| %>
    <% item.tags.each do |tag, articles| %>
        <span><%= link_to "#{tag}", tag_path(tag, 'werk') %></span>
    <% end %>
<% end %>

Thanks @jpmelguizo, I haven’t tried your solution yet but I will soon. Thank you (: