Refactoring code help

In my front matter for personnel, I have the following:

[profiles]
  blog = "https://blog.com"
  linkedin = "person"
  twitter = "person"
  ...

Not all persons have complete profiles. For instance, a person may only have a twitter account. This causes problems with knowing where to put the ",".

This code works, but it’s not DRY. Any suggestions on how to refactor?

{{$profile := slice}}
{{with .Params.profiles.blog}}
  {{$profile = $profile | append .}}
{{end}}
{{with .Params.profiles.linkedin}}
  {{$profile = $profile | append (print "https://linkedin.com/company/" .)}}
{{end}}
{{with .Params.profiles.twitter}}
  {{$profile = $profile | append (print "https://twitter.com/" .)}}
{{end}}
...

{{range $i, $e := $profile}}{{if $i}},{{end}}{{. | jsonify}}{{end}}

Is this supposed to be a Schema.org sameAs?

I’ll leave this here as reference, anyway:

Social platforms are stored in a data file.

you can use delimit function.

{{ delimit $profile "," }}