Meta name="keywords"

Hi,

I use a toml like this in my markdown-files:

+++
....
description   = "some more or less silly text"
keywords     = "word1, expression2, phrase3"
...
+++

and this in my header partial:

    <meta name="description" content="{{ .Description }}">
    <meta name="KEYWORDS" content="{{ .Keywords }}">

After running Hugo (0.17) this is rendered as follows:

    <meta name="description" content="some more or less silly text">
    <meta name="KEYWORDS" content="[word1, expression2, phrase3]">

How can I get rid of those [ ] in the rendered keywords metatag?

  {{ with .Keywords }}<meta name="keywords" content="{{ range $i, $e := . }}{{ if $i }}, {{ end }}{{ $e }}{{ end }}">{{ end }}
      

(on an unrelated side note: Hugo 0.17 is very old and I would recommend you update to something newer)

Before you spend too much time on those keyword metas read this: HEAD Tags. It’s a great explanation of all possible head tags. What you don’t find in there is the meta tag for keywords because those are no longer recommended (even by Google).

To your question: The keywords in Front Matter is a list and that has to be enclosed by square brackets like keywords = ["word1", "word2"]. I assume this solves your problem.

 <meta name="KEYWORDS" content="{{ .Params.keywords }}">

Have you tried this option?

I had to delete a comma after {{ if $i }} - and then it worked perfectly :smile: - many thanks.

Would do that but usually this breaks something in my templates and thus has to wait until I have some spare time around Christmas …
and sorry for confusion, I actually use v0.18.1 BuildDate: 2016-12-30T11:05:34+01:00 - last year Christmas time for exactly the same reason.

This renders as <meta name="KEYWORDS" content="[word1, word2]">

renders as <meta name="KEYWORDS" content="">

Thanks for this. Will have a closer look the next days …

This worked for me:

<meta name="keywords" content={{ delimit .Keywords " " }} />