How to Add a Canonical URL in Hugo

I was getting errors about canonical URLs in the Google console( “Page is not indexed: Duplicate without user-selected canonical”). After a little digging, it seems the fix is to add a link in the <head> tag to specify the canonical URL. This blog post shows how to accomplish this in Hugo. The solution looks like this:

    <link rel="canonical" href="{{ .Permalink }}">