Refactoring code help

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

  blog = ""
  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}}
  {{$profile = $profile | append .}}
{{with .Params.profiles.linkedin}}
  {{$profile = $profile | append (print "" .)}}
{{with .Params.profiles.twitter}}
  {{$profile = $profile | append (print "" .)}}

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

Is this supposed to be a sameAs?

I’ll leave this here as reference, anyway:

Social platforms are stored in a data file.

you can use delimit function.

{{ delimit $profile "," }}