Some sort of area dedicated to account settings that become Hugo parameters would likely be helpful. I remembered finding the Twitter username setting once and then totally failed to find it again when I was writing my social media links plugin.
The plugin injects <meta>
relationship tags in head via the use of a data file.
My data file looks like this:
# This file holds the array of social media platforms to link.
#
# The value of Href will be generated by substituting the value
# of USERNAME (as well as SERVER when set).
#
# Replace [BRACKETED] values and uncomment or create your own entries
# for platforms not listed.
#
[[Platforms]]
Name = "Twitter"
Href = "https://twitter.com/@USERNAME"
Username = "moondeerdotblog"
[[Platforms]]
Name = "Github"
Href = "https://github.com/USERNAME"
Username = "moonbuck"
[[Platforms]]
Name = "Tumblr"
Href = "https://USERNAME.tumblr.com"
Username = "moondeerdotblog"
[[Platforms]]
Name = "Medium"
Href = "https://USERNAME.medium.com"
Username = "Moondeer"
[[Platforms]]
Name = "Facebook"
Href = "https://www.facebook.com/USERNAME"
Username = "moondeerdotblog"
[[Platforms]]
Name = "Instagram"
Href = "https://www.instagram.com/USERNAME"
Username = "moondeerdotblog"
[[Platforms]]
Name = "Mastodon"
Href = "https://SERVER/@USERNAME"
Server = "mastodon.online"
Username = "moondeer"
which then generates these links in my page <head>
.
<link rel="me" href="https://micro.blog/Moondeer">
<link rel="me" href="https://twitter.com/@moondeerdotblog">
<link rel="me" href="https://github.com/moonbuck">
<link rel="me" href="https://moondeerdotblog.tumblr.com">
<link rel="me" href="https://Moondeer.medium.com">
<link rel="me" href="https://www.facebook.com/moondeerdotblog">
<link rel="me" href="https://www.instagram.com/moondeerdotblog">
<link rel="me" href="https://mastodon.online/@moondeer">
The lookup is generalized in a way that should allow for a user to enter additional platforms:
layouts/partials/head/social-media-links.html
{{- /* Pulls from data/plugin_sml/params.toml to generate the social media links */ -}}
{{ partial "head/social-media-link.html" (dict "Name" "Micro.blog" "Username" site.Author.username "Href" "https://micro.blog/USERNAME") }}
{{- $platforms := site.Data.plugin_sml_params.Platforms | default site.Data.plugin_sml.params.Platforms -}}
{{- range $platforms }}
{{ partial "head/social-media-link.html" . }}
{{- end }}
layouts/partials/head/social-media-link.html
{{- if (and .Name .Href) }}
{{- if .Username }}
{{- if (or .Server (not (in .Href "SERVER"))) }}
{{- $href := .Href }}
{{- if (in $href "SERVER") }}{{ $href = $href | replaceRE "SERVER" .Server }}{{ end }}
{{- $href = $href | replaceRE "USERNAME" .Username }}
<link rel="me" href="{{ $href | safeHTMLAttr }}" />
{{- end }}
{{- end }}
{{- end }}
The plugin also includes a partial that users can inject into their custom theme for displaying links (perhaps as part of a profile section):
layouts/partials/profile/social-media-links.html
{{- /* Pulls from data/plugin_sml/params.toml to generate the social media links */ -}}
<div id="social-media-links">
{{ partial "profile/social-media-link.html" (dict "Name" "Micro.blog" "Username" site.Author.username "Href" "https://micro.blog/USERNAME") }}
{{- $platforms := site.Data.plugin_sml_params.Platforms | default site.Data.plugin_sml.params.Platforms -}}
{{- range $platforms }}
{{ partial "profile/social-media-link.html" . }}
{{- end }}
</div>
layouts/partials/profile/social-media-link.html
{{- if (and .Name .Href) }}
{{- if .Username }}
{{- if (or .Server (not (in .Href "SERVER"))) }}
{{- $href := .Href }}
{{- if (in $href "SERVER") }}{{ $href = $href | replaceRE "SERVER" .Server }}{{ end }}
{{- $href = $href | replaceRE "USERNAME" .Username }}
<div id="{{ .Name }}" class="sml-container">
<a id="{{ .Name }}"
class="sml"
rel="me"
href="{{ $href | safeHTMLAttr }}">@{{ .Username }}</a>
<span id="{{ .Name }}" class="sml"> {{ .Name }}</span>
</div>
{{- end }}
{{- end }}
{{- end }}
Using the data file from above, my custom theme uses the plugin partial to stick the links in my profile:
layouts/partials/profile.html
<section id="author-profile" class="h-card">
<a class="u-url" rel="me" href="https://moondeer.blog/about">
{{- with site.Author.profileavatar | default site.Author.avatar }}
<img id="avatar" class="u-photo" src="{{ . }}" />
{{- end }}
</a>
<h1 class="p-name" rel="me">{{ site.Author.name }}</h1>
{{- partial "plugins/social-media-links.html" . }}
{{- $bio := cond .IsHome site.Author.briefbio site.Author.aboutbio -}}
<p id="brief-bio" class="p-note">{{ $bio }}</p>
</section>
layouts/partials/plugins/social-media-links.html
{{- if templates.Exists "partials/profile/social-media-links.html" -}}
<div id="social-media-links" class="p-role">
{{ partial "profile/social-media-links.html" . }}
</div>
{{- end -}}