INFINITEINK ├── layouts │ ├── _default │ │ └── baseof.html │ └── partials │ └── tootpick-partial.html └── static └── img └── mastodon └── logo-purple.svg
Nowadays many — maybe most — websites include a share button or link that you can use to easily share a web page to a social networking system. Until February 2023, the Infinite Ink website did not have any share buttons because I did not want to encourage Infinite Ink’s visitors to use any messaging system that’s not based on standards. But, now that I’m using Mastodon, which is based on standards (ActivityPub and WebFinger) and free/libre open source software,[2] I’ve decided to include a Share on Mastodon link on some Infinite Ink pages. This share link will, I hope…
help spread the word about Infinite Ink articles,
encourage Infinite Ink visitors to use Mastodon, and
make it easier for me to toot about Infinite Ink updates.
To learn about Mastodon, see Infinite Ink’s #mastodon portal.
This “How” section describes the steps I used to set this up. After these steps, some Infinite Ink pages include a link near the bottom of the page that looks something like this:
And a subset of the Infinite Ink Hugo project looks like this:
INFINITEINK ├── layouts │ ├── _default │ │ └── baseof.html │ └── partials │ └── tootpick-partial.html └── static └── img └── mastodon └── logo-purple.svg
There are a lot of ways to create a Share on Mastodon link, including…
I first tried share-on-mastodon.social, but did not like that I could not preview a toot without first specifying a Mastodon instance. Then I tried tootpick and, so far, I like it.
The four steps below describe how I set up tootpick.
static
First, I got the current
Mastodon
small purple logo (logo-purple.svg
) from
joinmastodon.org/branding
and put it in
the
static/img/mastodon/
directory.
tootpick-partial.html
Next, I created a Hugo partial that creates a page-specific tootpick.org link.
Create
the string
($text
)
that will be
tooted
by
using
Hugo’s printf
function
to
concatenate
.Title
, .RelPermalink
, #InfiniteInk
, and more.[3]
Use some of Hugo's text-tranformation functions to make this string safe for use in a URL.
Here is
Infinite Ink’s
layouts/partials/tootpick-partial.html
:
{{- /*
Path: layouts/partials/tootpick-partial.html
Created: 2023-February
*/ -}}
{{ $text := (printf "Check out "%s" at https://www.ii.com%s #InfiniteInk" .Title .RelPermalink) }}
<a href="https://tootpick.org/#plustospace=yes&text={{- $text | plainify | htmlUnescape | urlquery -}}"
rel="nofollow">
<nobr><img src="/img/mastodon/logo-purple.svg" width="16" style="max-width: 100%;"> Share on Mastodon</nobr>
</a>
To learn about Tootpick, which is a privacy-preserving tooter, see github.com/Juerd/tootpick.
To learn about Tootpick’s plustospace
parameter,
which is needed because
Hugo’s urlquery
function
encodes a space as +
rather that %20
, see
github.com/Juerd/tootpick#fragment-parameters.
To learn about Hugo’s
plainify
, htmlUnescape
, and urlquery
functions,
see
Infinite Ink’s
Transforming Text with Hugo.
💡 | The
author of tootpick ,
Juerd Waalboer,
toots
at
@whreq@hsnl.social. |
tootpick-partial
from baseof.html
Next, I included the following
in the
“Discuss or share”
section
of layouts/_default/baseof.html
.
{{ partial "tootpick-partial" . }}
Finally,
I ran the hugo server
command,
viewed the rendered
“Discuss or share”
sections
and
made sure that
the above
steps 1, 2, and 3 worked
by clicking
Share on Mastodon.
To test this on this page,
go to the
Discuss or share section
below.
For more about Hugo, see Infinite Ink’s…
A Way to Compare Hugo’s Markup Languages (featuring inline footnotes)📊
🔗 Linkified Section Headings in Hugo-Generated Web Pages (featuring Markdown and AsciiDoc examples)
Hugo Shortcodes: How to Include Go Templates in Hugo Content Files
Hugo’s .RenderString
Method (featuring AsciiDoc admonitions in Markdown and Go HTML)
Variable and Parameter Names in Hugo (featuring camelCase🐫 and snake_case🐍)
Hugo’s Markup Languages: AsciiDoc, HTML, Markdown,
Transforming Text with Hugo (featuring plainify
, htmlUnescape
, and more)
Configuring Security in Hugo (featuring settings needed to use Asciidoctor and Pandoc)🔒
TGIH: Themeless & Gitless Introduction to the Hugo SSG (a tutorial👩🏫)
.Title
and .RelPermalink
are built-in Hugo page variables. $text
is a user-defined (also known as custom) variable.@nm@mathstodon.xyz
or
#InfiniteInk
in it.