runhide
September 4, 2020, 9:42pm
#1
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}}
sephore
September 4, 2020, 9:49pm
#2
Is this supposed to be a Schema.org sameAs
?
I’ll leave this here as reference, anyway:
{{ with .Lastmod }}"dateModified": "{{ .Format "2006-01-02" | safeHTML }}",{{ end }}
"wordCount" : "{{ .WordCount }}",
"publisher": {
"@type": "Person",
"name": "{{ .Site.Params.author }}"
},
"author": {
"@type": "Person",
"name": "{{ .Site.Params.author }}",
{{ with .Site.Params.authorDesc }}"description": {{ . }},{{ end }}
{{ if gt (len $sameAs) 0 }}"sameAs": {{ $sameAs }}{{ end }}
}
}
</script>
{{ else }}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "{{ .Site.BaseURL }}",
"inLanguage": "{{ .Site.Language.Lang }}",
Social platforms are stored in a data file .
pamubay
September 5, 2020, 1:51am
#3
you can use delimit
function.
{{ delimit $profile "," }}