# Refactoring code help

**URL:** <https://discourse.gohugo.io/t/refactoring-code-help/28020>\
**Category:** support\
**Created:** [September 4, 2020, 9:42pm UTC](https://discourse.gohugo.io/t/refactoring-code-help/28020 "2020-09-04T21:42:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![runhide](https://avatars.discourse-cdn.com/v4/letter/r/eada6e/32.png) [@runhide](https://discourse.gohugo.io/u/runhide)\
**Post date:** [September 4, 2020, 9:42pm UTC](https://discourse.gohugo.io/t/refactoring-code-help/28020/1 "2020-09-04T21:42:42Z")

</div>

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}}
```

---

<div class="post-metadata">

**Author:** ![sephore](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sephore/32/11673_2.png) [@sephore](https://discourse.gohugo.io/u/sephore)\
**Post date:** [September 4, 2020, 9:49pm UTC](https://discourse.gohugo.io/t/refactoring-code-help/28020/2 "2020-09-04T21:49:59Z")

</div>

Is this supposed to be a [Schema.org](http://Schema.org) `sameAs`?

I’ll leave this here as reference, anyway:

> <https://github.com/rmaguiar/hugo-theme-color-your-world/blob/master/layouts/partials/head.html#L322>

Social platforms are stored in a [data file](https://github.com/rmaguiar/hugo-theme-color-your-world/blob/master/data/social.json).

---

<div class="post-metadata">

**Author:** ![pamubay](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pamubay/32/17838_2.png) [@pamubay](https://discourse.gohugo.io/u/pamubay)\
**Post date:** [September 5, 2020, 1:51am UTC](https://discourse.gohugo.io/t/refactoring-code-help/28020/3 "2020-09-05T01:51:00Z")

</div>

> [@runhide](#):
>
> `{{range $i, $e := $profile}}{{if $i}},{{end}}{{. | jsonify}}{{end}}`

you can use `delimit` function.

```auto
{{ delimit $profile "," }}

```

> **[collections.Delimit](https://gohugo.io/functions/collections/delimit/)**
>
> Loops through any array, slice, or map and returns a string of all the values separated by a delimiter.
