Lost with string manipulation in a partial

Hello,

I’m trying to add hyperlinks to authors from a list in the front matter of a page:

author: ["[K. Frog](https://example.org)","[M. Piggie](https://example.com)","AN. Other"]

Not all authors have a URL associated with their name.

I have a partial (author.html) that splits quote enclosed authors, but I don’t understand enough Go string manipulation to modify this to add a link to each name, if a link is part of the author string.

{{- if .Params.author }}
{{- $author := .Params.author }}
{{- $author_type := (printf "%T" $author) }}
{{- if (or (eq $author_type "[]string") (eq $author_type "[]interface {}")) }}
{{- (delimit $author ", " ) }}
{{- else }}
{{- $author }}
{{- end }}
{{- end -}}

The output I’m looking for given the front matter input would be K. Frog, M. Piggie, AN. Other

Any help or pointers gratefully received.

The idiomatic way to handle authors is with an authors taxonomy.

site configuration

[taxonomies]
author = 'authors'

content/posts/post-1.md

---
title: Post 1
date: 2021-01-01T00:00:00-00:00
draft: false
authors:
- kfrog
- mpiggie
---

content structure

content/
├── authors/
│   ├── kfrog/
│   │   └── _index.md  <-- contains author metadata (name, profile url, image, etc.)
│   └── mpiggie/
│       └── _index.md  <-- contains author metadata (name, profile url, image, etc.)
├── posts/
│   └── post-1.md
└── _index.md

content/authors/kfrog/_index.md

---
title: K. Frog
date: 2023-07-20T13:12:19-07:00
draft: false
profile: https://example.org/kfrog  <-- do not use `url` as the key; that's reserved
---

layouts/_default/single.html

{{ with .GetTerms "authors" }}
  <p>Authors:</p>
  <ul>
    {{ range . }}
      <li>
        <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
        (<a href="{{ .Params.profile }}">profile</a>)
      </li>
    {{ end }}
  </ul>
{{ end }}

rendered

image

Thank you for your reply, I had considered doing it this way, and this would work for pages authored on-site. However, the authors I’m referring to are generated from a bibtext file I parse to extract journal titles, author names and associated URLs (Often google scholar links, or links to person websites.

Essentially I’m producing a pager per publication from the bibtex, with most of the content automagically generated, it’s just the author name / url that’s flummoxed me.

Given your front matter example, this:

{{ range .Params.author }}
  {{ . | markdownify }}
{{ end }}

produces this:

image

Thank you - that gets me what I want. I really appreciate your help.

If you want to insert a delimiter…

{{- range $k, $_ := .Params.author }}
  {{- if $k }}&thinsp;{{ end }}
  {{- . | markdownify }}
{{- end }}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.