Remove Duplicates from Map of Taxonomies

Hello Community,

i am having a little trouble removing duplicates from a map (at least i think it’s a map?)

The core of my Problem comes down to the output of this example-code:

<ul>
  {{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
    <li><a href="{{ "/" | relLangURL}}{{ $taxonomyname | urlize }}">{{ $taxonomyname }}</a>
      <ul>
        {{ range $key, $value := $taxonomy }}
        <li> {{ $key }} </li>
              <ul>
              {{ range $value.Pages | uniq }}
                  <li><a href="{{ .Permalink}}"> {{ .LinkTitle }} </a> </li>
              {{ end }}
              </ul>
        {{ end }}
      </ul>
    </li>
  {{ end }}
</ul>

This is from Taxonomy methods and this should output every Post exactly once sorted under the tags and the taxonomies…

However in my case every Post is in there two times like:

taxonomy-y:
    tag-a:
        - asdf
        - asdf
        - ghjk
        - ghjk
    tag-b:
        - Lorem
        - Lorem
        - Ipsum
        - Ipsum
taxonomy-x:
    tag-42:
        - Dolor
        - Dolor
        - Sit
        - Sit

instead of the expected:

taxonomy-y:
    tag-a:
        - asdf
        - ghjk
    tag-b:
        - Lorem
        - Ipsum
taxonomy-x:
    tag-42:
        - Dolor
        - Sit

Could this have to do something with the fact that i set permalinks for the taxonomies?

I tried to apply a solution like the one on Remove duplicates from Array? but no luck until now.

Info:

  • hugo v0.82.0+extended darwin/amd64 BuildDate=unknown
  • macOS 10.15.7

I am unable to reproduce the problem as described. Try it:

git clone --single-branch -b hugo-forum-topic-40107 https://github.com/jmooring/hugo-testing hugo-forum-topic-40107
cd hugo-forum-topic-40107
hugo server
1 Like

Yes, i tried that and it works as expected.

    categories
        category-a
            Post 2
            Post 1
        category-b
            Post 2
            Post 1
    tags
        tag-a
            Post 2
            Post 1
        tag-b
            Post 2
            Post 1

First of all, thank you for your effort in trying to recreate the problem.
Unfortunately i don’t know what else to share to help you help me narrow the problem down…

How about your project repository?

2 Likes

Okay, so I was able to solve the problem now. It was a layer-8-one. :wink:

When I tried to change the taxonomy I duplicated the old content and didn’t delete it afterwards. Unfortunately I was working on other bugs (features) in the meantime and forgot about it. So there were actually duplicate posts and I got hung up on the layout-code…

Again @jmooring thank you for your support.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.