Hi all, big Hugo fan. Hope you can help: I’ve been tearing my hair out about how even to approach this.
What I want is to be able to include <uri> values for blog post coauthors in the Atom feed I’ve set up for my site. Here’s an example of my desired output in index.atom.xml for a sample <entry> with two coauthors:
Right now I’ve set up coauthors by setting an authors taxonomy and calling the authors with .Params.authors, and I can easily set up individual author pages with metadata for each author term that includes that author’s <uri>, but I can’t figure out how to attach that metadata to the correct authors in each post. I don’t particularly need individual author pages in any case, so I’m not married to the authors taxonomy.
I suspect that a better approach is either 1) to add author data in the /data directory and draw on that or 2) to hard code the author maps into the front matter TOML of each post, but I’ve had trouble with both of those.
Have consulted Multiple Authors Support in Hugo Website - Coding N Concepts but that only works for multiple authors on a site, not on a post. I’ve figured out how to put one or more author data files in /data and display that data for posts with a single author, but not how to say, in essence, “Find each of the authors of this post in the /data directory and display the corresponding uri value for that author.”
Have also read posts like Maps in front matter? and that syntax doesn’t break anything, but I can’t figure out how to call each author from that map.
Even advice about which approach is best and where to start reading would help!
{{- $pctx := . }}
{{- if .IsHome }}{{ $pctx = .Site }}{{ end }}
{{- $pages := slice }}
{{- if or $.IsHome $.IsSection }}
{{- $pages = $pctx.RegularPages }}
{{- else }}
{{- $pages = $pctx.Pages }}
{{- end }}
{{- $limit := .Site.Config.Services.RSS.Limit }}
{{- if ge $limit 1 }}
{{- $pages = $pages | first $limit }}
{{- end }}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ .Site.Title }}</description>
<generator>Hugo</generator>
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }}
<managingEditor>{{.}}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with .Site.Copyright }}
<copyright>{{ . }}</copyright>{{ end }}{{ if not .Date.IsZero }}
<lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
{{- end }}
{{- range $pages }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{- range .GetTerms "authors" }}
<author>
<name>{{ .Page.Title }}</name>
{{ with .Page.Params.uri }}<uri>{{ . }}</uri>{{ end }}
</author>
{{- end }}
<guid>{{ .Permalink }}</guid>
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>
</item>
{{- end }}
</channel>
</rss>
Try it
git clone --single-branch -b hugo-forum-topic-53373 https://github.com/jmooring/hugo-testing hugo-forum-topic-53373
cd hugo-forum-topic-53373
hugo server