The title example is probably why I am confused to making this work - lol
I am trying to retrieve values from .Site.Data.contributors
only where they match to the front matter contributor.name
.
Hopefully the code bellow makes more sense(?).
The Front Matter:
+++
[[contributor]]
name = "John Doe"
[[contributor]]
name = "Jane Doe"
+++
/data/contributors.toml:
[John-Doe]
name = "John Doe"
role = ["author","editor"]
guid = "7ce177def422404391300b286481f157"
bio = "This is John Doe's Bio"
avatar = "john-doe.jpg"
avatarCaption = "A nerd"
links = [
"https://www.instagram.com/.../",
"https://500px.com/p/...",
"https://www.linkedin.com/in/.../"
]
[Jane-Doe]
name = "Jane Doe"
role = ["author","editor"]
guid = "025c964413724f7fa7b402c283b74ee9"
bio = "This is Jane Doe's Bio"
avatar = "jane-doe.jpg"
avatarCaption = "Also a nerd"
links = [
"https://www.instagram.com/.../",
"https://500px.com/p/...",
"https://www.linkedin.com/in/.../"
]
[Grease-Monkey]
name = "Grease Monkey"
role = ["author","editor"]
guid = "025c964413724f7fa7b402c283b74ee9"
bio = "This is Grease Monkey's Bio"
avatar = "grease-monkey.jpg"
avatarCaption = "Also a nerdy-monkey"
links = [
"https://www.instagram.com/.../",
"https://500px.com/p/...",
"https://www.linkedin.com/in/.../"
]
The HTML:
NOTE: .name
parses correctly but everything else seems to returns nul
{{- $baseURL := substr .Site.BaseURL 0 -1 -}}
{{- $imgCDN := .Site.Params.cloudinaryURL -}}
{{- $avatarSRC := printf "%s%s" $imgCDN "/static/avatars/" -}}
{
"@type" : "contributor",
"person": [
{{ range .Params.contributor }}
{{- $data := $.Site.Data.contributors -}}
{{- $contributorPath:= printf "%s%s" $baseURL "/about/contributors/" -}}
{{- $name := replace .name " " "-" -}}
{{- $contributorURL := printf "%s%s" $contributorPath $name -}}
{{- $GUID := printf "%s%s" "/#/schema/person/" .guid }}
{
"@type" : "Person",
"@id" : "{{- printf "%s%s" $baseURL $GUID }}",
"name" : "{{- .name -}}",
"url" : "{{- $contributorURL -}}",
"image" : {
"@type" : "ImageObject",
"@id" : "{{- printf "%s%s" $contributorURL "/#avatar" -}}",
"contentUrl" : "{{- printf "%s%s" $avatarSRC .avatar -}}",
"caption" : "{{- .avatarCaption | safeHTML -}}",
"inLanguage" : "en-US"
},
"description": "{{- .bio | safeHTML -}}",
"sameAs" : [
{{- range $comma, $e := .links -}}
{{- if $comma -}},{{- end }}
"{{ . }}"{{- end }}
]
}{{ end }}
]
}
Currently Outputs as:
...
},{
"@type" : "contributor",
"person": [
{
"@type" : "Person",
"@id" : "https://stageing.xyz.com/#/schema/person/%!s(<nil>)",
"name" : "John Doe",
"url" : "https://stageing.xyz.com/about/contributors/John-Doe",
"image" : {
"@type" : "ImageObject",
"@id" : "https://stageing.xyz.com/about/contributors/John-Doe/#avatar",
"contentUrl" : "https://res.cloudinary.com/xyz/image/upload/static/avatars/%!s(<nil>)",
"caption" : "",
"inLanguage" : "en-US"
},
"description": "",
"sameAs" : [
]
}
{
"@type" : "Person",
"@id" : "https://stageing.xyz.com/#/schema/person/%!s(<nil>)",
"name" : "Jane Doe",
"url" : "https://stageing.xyz.com/about/contributors/Jane-Doe",
"image" : {
"@type" : "ImageObject",
"@id" : "https://stageing.xyz.com/about/contributors/Jane-Doe/#avatar",
"contentUrl" : "https://res.cloudinary.com/xyz/image/upload/static/avatars/%!s(<nil>)",
"caption" : "",
"inLanguage" : "en-US"
},
"description": "",
"sameAs" : [
]
}
]
}]
The debug for $.Site.Data.contributors
:
map[string]interface {}{"Jane-Doe":map[string]interface {}{"avatar":"jane-doe.jpg", "avatarCaption":"Even Nerdier", "bio":"This is Jane Doe's Bio", "guid":"c4ec735a3eaa4e5eb1f6ef23deb03931", "links":[]interface {}{"https://"}, "name":"Jane Doe", "role":[]interface {}{"founder", "photographer", "author", "editor"}}}}]
…