Adding "uniq" to template functions

One of the reasons I haven’t moved my site over to Hugo is that I was getting duplicate breadcrumbs entries on my blog’s back pages (/blog/page/2/, /blog/page/3/, etc.). Recently I figured that I could solve my problem well enough if there were a uniq function to throw out the duplicate entries in the list of parent pages. There wasn’t one, so I made one.

I’ll be the first to admit that I don’t know what I’m doing with reflect, but it seems to work well for the tests I adapted from TestUnion() and it does what I want it to on my site. I’m not sure what’s next: I watch spf13/hugo on Github and it seems like most of the conversations there have a second post that says “discuss this on the forums first”, so I’m opening the conversation here. I’d be happy to submit a pull request and make any changes needed to make this Hugo-quality.

I was about to do the git rebase -i dance to squash my four commits, but Git told me that I had uncommitted changes that needed to be stashed before I could do that. My vendor/vendor.json changed a bit and I’m not sure what’s going on. I’m pretty sure I ran make vendor when hugo was in $GOPATH/src/hugo instead of $GOPATH/src/github.com/spf13/hugo, but I don’t know if I should worry about the SHA1 differences. Here’s the diff of what my vendor/vendor.json looks like now:

diff --git a/vendor/vendor.json b/vendor/vendor.json
index 73cb86a8..59c73725 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -359,19 +359,19 @@
            "revisionTime": "2017-05-22T23:30:54Z"
        },
        {
-			"checksumSHA1": "wxrHmKhFznZZAjrYK5/nWn+fZGc=",
+			"checksumSHA1": "4owIzLmRdrdy3H3j/OD8UMJD5ZE=",
            "path": "golang.org/x/sys/unix",
            "revision": "dbc2be9168a660ef302e04b6ff6406de6f967473",
            "revisionTime": "2017-05-20T17:05:02Z"
        },
        {
-			"checksumSHA1": "DoQpPb6ZhqN2gP7rNXfxHaTUgEs=",
+			"checksumSHA1": "DWHpSSH7hmB31XvpQqFDshcRU+4=",
            "path": "golang.org/x/text/cases",
            "revision": "19e51611da83d6be54ddafce4a4af510cb3e9ea4",
            "revisionTime": "2017-04-21T08:09:44Z"
        },
        {
-			"checksumSHA1": "9Px0J1fbo4RT0sxn40pPUZOEdhM=",
+			"checksumSHA1": "A9N3+Wl4MedhMJZIlun1LXXCCNI=",
            "path": "golang.org/x/text/internal",
            "revision": "19e51611da83d6be54ddafce4a4af510cb3e9ea4",
            "revisionTime": "2017-04-21T08:09:44Z"
@@ -383,7 +383,7 @@
            "revisionTime": "2017-04-21T08:09:44Z"
        },
        {
-			"checksumSHA1": "Dhc7bHUc+d1uuYO/byxQf7AfW+o=",
+			"checksumSHA1": "ckawpDnd22U/0HjSPKF4yY5pIeg=",
            "path": "golang.org/x/text/language",
            "revision": "19e51611da83d6be54ddafce4a4af510cb3e9ea4",
            "revisionTime": "2017-04-21T08:09:44Z"
@@ -401,7 +401,7 @@
            "revisionTime": "2017-04-21T08:09:44Z"
        },
        {
-			"checksumSHA1": "cvRGMfzfSIW0uZ9V2Px24q512Ks=",
+			"checksumSHA1": "xO6ERghp1RGU9RM2t6ykY0cK1g0=",
            "path": "golang.org/x/text/secure/precis",
            "revision": "19e51611da83d6be54ddafce4a4af510cb3e9ea4",
            "revisionTime": "2017-04-21T08:09:44Z"
@@ -413,19 +413,19 @@
            "revisionTime": "2017-04-21T08:09:44Z"
        },
        {
-			"checksumSHA1": "KG+XZAbxdkpBm3Fa3bJ3Ylq8CKI=",
+			"checksumSHA1": "MRLtTu/vpd18le8/HPLxOdjO5RE=",
            "path": "golang.org/x/text/unicode/bidi",
            "revision": "19e51611da83d6be54ddafce4a4af510cb3e9ea4",
            "revisionTime": "2017-04-21T08:09:44Z"
        },
        {
-			"checksumSHA1": "Anof4bt0AU+Sa3R8Rq0KBnlpbaQ=",
+			"checksumSHA1": "kKylzIrLEnH8NKyeVAL0dq5gjVQ=",
            "path": "golang.org/x/text/unicode/norm",
            "revision": "19e51611da83d6be54ddafce4a4af510cb3e9ea4",
            "revisionTime": "2017-04-21T08:09:44Z"
        },
        {
-			"checksumSHA1": "/kqvbsH5mRknhs6xf7cJii0wQos=",
+			"checksumSHA1": "aCXemG0knLp8YJedta7fYAIiX/8=",
            "path": "golang.org/x/text/width",
            "revision": "19e51611da83d6be54ddafce4a4af510cb3e9ea4",
            "revisionTime": "2017-04-21T08:09:44Z"
@@ -437,5 +437,5 @@
            "revisionTime": "2017-04-07T17:21:22Z"
        }
    ],
-	"rootPath": "github.com/spf13/hugo"
+	"rootPath": "hugo"
 }

Hi. Did you get a response to your pull request?

Yup. After a bit of back-and-forth making the pull request better, it’s been integrated into the main branch on spf13/hugo.

1 Like