SEO optimisation - mimicking Wordpress plugin functionality

Hi,

I recently decided to ditch Wordpress and am developing a Hugo theme (using Bulma) to suit my needs.

One partial I am building is an SEO check in the same style as the Yoast Wordpress plugin.

This is what it looks like:

Almost all functionality works. The dashboard only appears when running on localhost.

One check I cannot seem to work out.

I use a custom parameter called keyphrase on each page. The test is whether the keyphrase on a certain page has a duplicate in another page. I tried to range over .Site.RegularPages and list all keyphrases.

Question: How can I count the number of times a term occurs in a list?

Peter

Thanks, that helped me create a solution by adding a counter, using:

{{ $.Scratch.Set "count" 0 }}
{{ range .Site.RegularPages }}
{{ if eq .Params.keyphrase $kph }}
{{ $.Scratch.Add "count" 1 }}
{{ end }}
{{ end }}
{{ $nkp := $.Scratch.Get "count" }}
1 Like

And I guess you also can do that this way (use := & =)

{{ $counter := 0 }}
{{ range .Site.RegularPages }}
  {{ if eq .Params.keyphrase $kph }}
    {{ $counter = add $counter 1 }}
  {{ end }}
{{ end }}
{{ $nkp := $counter }}
2 Likes

Thanks, that works great and is a bit more elegant.

I also removed the last line as I can use the counter variable for the display.

1 Like

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